Class: Lutaml::Qea::Benchmark
- Inherits:
-
Object
- Object
- Lutaml::Qea::Benchmark
- Defined in:
- lib/lutaml/qea/benchmark.rb
Overview
Performance benchmarking utilities for comparing QEA vs XMI parsing
Class Method Summary collapse
-
.compare(qea_path, xmi_path) ⇒ Hash
Compare QEA and XMI parsing performance.
-
.format_results(results) ⇒ String
Format benchmark results for display.
-
.measure_qea(path) ⇒ Hash
Measure QEA parsing performance.
-
.measure_xmi(path) ⇒ Hash
Measure XMI parsing performance.
Class Method Details
.compare(qea_path, xmi_path) ⇒ Hash
Compare QEA and XMI parsing performance
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lutaml/qea/benchmark.rb', line 26 def compare(qea_path, xmi_path) # rubocop:disable Metrics/MethodLength qea_result = measure_qea(qea_path) xmi_result = measure_xmi(xmi_path) speedup = if qea_result[:time].positive? (xmi_result[:time] / qea_result[:time]).round(2) else 0 end { qea: qea_result, xmi: xmi_result, speedup: speedup, improvement_percent: ((speedup - 1) * 100).round(1), } end |
.format_results(results) ⇒ String
Format benchmark results for display
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/lutaml/qea/benchmark.rb', line 147 def format_results(results) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity return results[:error] if results[:error] output = [] output << ("=" * 80) output << "QEA vs XMI Performance Comparison" output << ("=" * 80) output << "" if results[:qea][:error] output << "QEA Error: #{results[:qea][:error]}" else output << "QEA File:" output << " Path: #{results[:qea][:file]}" output << " Size: #{results[:qea][:file_size_mb]} MB" output << " Parse Time: #{results[:qea][:time]}s" if results[:qea][:throughput_mb_per_sec] output << " Throughput: " \ "#{results[:qea][:throughput_mb_per_sec]} MB/s" end output << " Packages: #{results[:qea][:stats][:packages]}" output << " Classes: #{results[:qea][:stats][:classes]}" end output << "" if results[:xmi][:error] output << "XMI Error: #{results[:xmi][:error]}" else output << "XMI File:" output << " Path: #{results[:xmi][:file]}" output << " Size: #{results[:xmi][:file_size_mb]} MB" output << " Parse Time: #{results[:xmi][:time]}s" if results[:xmi][:throughput_mb_per_sec] output << " Throughput: " \ "#{results[:xmi][:throughput_mb_per_sec]} MB/s" end output << " Packages: #{results[:xmi][:stats][:packages]}" output << " Classes: #{results[:xmi][:stats][:classes]}" end output << "" output << "Performance Improvement:" output << " QEA is #{results[:speedup]}x faster than XMI" output << " Improvement: #{results[:improvement_percent]}%" output << "" # Add interpretation output << if results[:speedup] >= 10 " ✓ Significant performance improvement with QEA" elsif results[:speedup] >= 5 " ✓ Notable performance improvement with QEA" elsif results[:speedup] >= 2 " ✓ Moderate performance improvement with QEA" else " ~ Minimal performance difference" end output << ("=" * 80) output.join("\n") end |
.measure_qea(path) ⇒ Hash
Measure QEA parsing performance
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/lutaml/qea/benchmark.rb', line 53 def measure_qea(path) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity unless File.exist?(path) return { error: "File not found: #{path}" } end result = { file: path, file_size_mb: (File.size(path) / 1024.0 / 1024.0).round(2), format: "QEA", } # Measure parsing time document = nil time = ::Benchmark.realtime do document = Lutaml::Qea.parse(path) end result[:time] = time.round(3) result[:stats] = { packages: document.packages&.size || 0, classes: document.classes&.size || 0, associations: document.associations&.size || 0, diagrams: document.diagrams&.size || 0, } # Calculate throughput if result[:file_size_mb].positive? && time.positive? result[:throughput_mb_per_sec] = (result[:file_size_mb] / time).round(2) end result rescue StandardError => e { error: e., file: path, format: "QEA", } end |
.measure_xmi(path) ⇒ Hash
Measure XMI parsing performance
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/lutaml/qea/benchmark.rb', line 101 def measure_xmi(path) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity unless File.exist?(path) return { error: "File not found: #{path}" } end result = { file: path, file_size_mb: (File.size(path) / 1024.0 / 1024.0).round(2), format: "XMI", } # Measure parsing time document = nil time = ::Benchmark.realtime do File.open(path) do |file| document = Lutaml::Xmi::Parsers::Xml.parse(file) end end result[:time] = time.round(3) result[:stats] = { packages: document.packages&.size || 0, classes: document.classes&.size || 0, associations: document.associations&.size || 0, diagrams: document.diagrams&.size || 0, } # Calculate throughput if result[:file_size_mb].positive? && time.positive? result[:throughput_mb_per_sec] = (result[:file_size_mb] / time).round(2) end result rescue StandardError => e { error: e., file: path, format: "XMI", } end |