lib/benchmark_driver/runner/once.rb in benchmark_driver-0.10.16 vs lib/benchmark_driver/runner/once.rb in benchmark_driver-0.11.0
- old
+ new
@@ -1,7 +1,7 @@
require 'benchmark_driver/struct'
-require 'benchmark_driver/metrics'
+require 'benchmark_driver/metric'
require 'benchmark_driver/default_job'
require 'benchmark_driver/default_job_parser'
require 'tempfile'
require 'shellwords'
@@ -10,64 +10,60 @@
# JobParser returns this, `BenchmarkDriver::Runner.runner_for` searches "*::Job"
Job = Class.new(BenchmarkDriver::DefaultJob)
# Dynamically fetched and used by `BenchmarkDriver::JobParser.parse`
JobParser = BenchmarkDriver::DefaultJobParser.for(Job)
- METRICS_TYPE = BenchmarkDriver::Metrics::Type.new(unit: 'i/s')
+ METRIC = BenchmarkDriver::Metric.new(name: 'Iteration per second', unit: 'i/s')
# @param [BenchmarkDriver::Config::RunnerConfig] config
- # @param [BenchmarkDriver::Output::*] output
+ # @param [BenchmarkDriver::Output] output
def initialize(config:, output:)
@config = config
@output = output
end
# This method is dynamically called by `BenchmarkDriver::JobRunner.run`
# @param [Array<BenchmarkDriver::Default::Job>] jobs
def run(jobs)
- @output.metrics_type = METRICS_TYPE
+ @output.metrics = [METRIC]
jobs = jobs.map do |job|
Job.new(job.to_h.merge(loop_count: 1)) # to show this on output
end
@output.with_benchmark do
jobs.each do |job|
- @output.with_job(job) do
+ @output.with_job(name: job.name) do
job.runnable_execs(@config.executables).each do |exec|
- metrics = run_benchmark(job, exec: exec) # no repeat support
- @output.report(metrics)
+ duration = run_benchmark(job, exec: exec) # no repeat support
+ @output.with_context(name: exec.name, executable: exec, duration: duration, loop_count: 1) do
+ @output.report(value: 1.0 / duration, metric: METRIC)
+ end
end
end
end
end
end
private
# @param [BenchmarkDriver::Runner::Ips::Job] job - loop_count is not nil
# @param [BenchmarkDriver::Config::Executable] exec
- # @return [BenchmarkDriver::Metrics]
+ # @return [Float] duration
def run_benchmark(job, exec:)
benchmark = BenchmarkScript.new(
prelude: job.prelude,
script: job.script,
teardown: job.teardown,
loop_count: job.loop_count,
)
- duration = Tempfile.open(['benchmark_driver-', '.rb']) do |f|
+ Tempfile.open(['benchmark_driver-', '.rb']) do |f|
with_script(benchmark.render(result: f.path)) do |path|
execute(*exec.command, path)
end
Float(f.read)
end
-
- BenchmarkDriver::Metrics.new(
- value: 1.0 / duration,
- duration: duration,
- executable: exec,
- )
end
def with_script(script)
if @config.verbose >= 2
sep = '-' * 30