Class: XmlCompilerBenchmarkRunner
- Inherits:
-
Object
- Object
- XmlCompilerBenchmarkRunner
- Defined in:
- lib/tasks/xml_compiler_benchmark.rb
Overview
Runner class compatible with existing infrastructure
Instance Method Summary collapse
-
#initialize(run_time: nil) ⇒ XmlCompilerBenchmarkRunner
constructor
A new instance of XmlCompilerBenchmarkRunner.
- #run_benchmarks ⇒ Object
Constructor Details
#initialize(run_time: nil) ⇒ XmlCompilerBenchmarkRunner
Returns a new instance of XmlCompilerBenchmarkRunner.
176 177 178 179 |
# File 'lib/tasks/xml_compiler_benchmark.rb', line 176 def initialize(run_time: nil, **) @run_time = run_time || 5 @schemas = XmlCompilerBenchmarks::SCHEMAS end |
Instance Method Details
#run_benchmarks ⇒ Object
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 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/tasks/xml_compiler_benchmark.rb', line 181 def run_benchmarks results = {} job = Benchmark::IPS::Job.new job.config(time: @run_time, warmup: 2) job.report("xml_compiler_small") do Lutaml::Model::Schema::XmlCompiler.to_models( @schemas[:small], load_classes: false, create_files: false, module_namespace: "Small", ) end job.report("xml_compiler_medium") do Lutaml::Model::Schema::XmlCompiler.to_models( @schemas[:medium], load_classes: false, create_files: false, module_namespace: "Medium", ) end job.run job.full_report.entries.each do |entry| samples = entry.stats.samples mean = samples.sum.to_f / samples.size variance = samples.sum { |x| (x - mean)**2 } / (samples.size - 1) std_dev = Math.sqrt(variance) error_margin = std_dev / mean lower = (mean * (1 - error_margin)).round(4) upper = (mean * (1 + error_margin)).round(4) results[entry.label.to_sym] = { lower: lower, upper: upper } end results end |