lib/benchmark_driver/runner/ips.rb in benchmark_driver-0.11.1 vs lib/benchmark_driver/runner/ips.rb in benchmark_driver-0.12.0
- old
+ new
@@ -5,41 +5,39 @@
require 'tempfile'
require 'shellwords'
# Show iteration per second.
class BenchmarkDriver::Runner::Ips
+ METRIC = BenchmarkDriver::Metric.new(name: 'Iteration per second', unit: 'i/s')
+
# 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)
+ JobParser = BenchmarkDriver::DefaultJobParser.for(klass: Job, metrics: [METRIC])
- METRIC = BenchmarkDriver::Metric.new(name: 'Iteration per second', unit: 'i/s')
-
# @param [BenchmarkDriver::Config::RunnerConfig] config
# @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 = [metric]
-
if jobs.any? { |job| job.loop_count.nil? }
@output.with_warmup do
jobs = jobs.map do |job|
next job if job.loop_count # skip warmup if loop_count is set
@output.with_job(name: job.name) do
executable = job.runnable_execs(@config.executables).first
duration, loop_count = run_warmup(job, exec: executable)
value, duration = value_duration(duration: duration, loop_count: loop_count)
- @output.with_context(name: executable.name, executable: executable, duration: duration, loop_count: loop_count) do
- @output.report(value: value, metric: metric)
+ @output.with_context(name: executable.name, executable: executable) do
+ @output.report(values: { metric => value }, duration: duration, loop_count: loop_count)
end
loop_count = (loop_count.to_f * @config.run_duration / duration).floor
Job.new(job.to_h.merge(loop_count: loop_count))
end
@@ -53,11 +51,11 @@
job.runnable_execs(@config.executables).each do |exec|
repeat_params = { config: @config, larger_better: true, rest_on_average: :average }
value, duration = BenchmarkDriver::Repeater.with_repeat(repeat_params) do
run_benchmark(job, exec: exec)
end
- @output.with_context(name: exec.name, executable: exec, duration: duration) do
- @output.report(value: value, metric: metric)
+ @output.with_context(name: exec.name, executable: exec) do
+ @output.report(values: { metric => value }, duration: duration, loop_count: job.loop_count)
end
end
end
end
end