lib/benchmark_driver/runner/once.rb in benchmark_driver-0.12.0 vs lib/benchmark_driver/runner/once.rb in benchmark_driver-0.13.0

- old
+ new

@@ -14,13 +14,15 @@ # Dynamically fetched and used by `BenchmarkDriver::JobParser.parse` JobParser = BenchmarkDriver::DefaultJobParser.for(klass: Job, metrics: [METRIC]) # @param [BenchmarkDriver::Config::RunnerConfig] config # @param [BenchmarkDriver::Output] output - def initialize(config:, output:) + # @param [BenchmarkDriver::Context] contexts + def initialize(config:, output:, contexts:) @config = config @output = output + @contexts = contexts end # This method is dynamically called by `BenchmarkDriver::JobRunner.run` # @param [Array<BenchmarkDriver::Default::Job>] jobs def run(jobs) @@ -29,13 +31,13 @@ end @output.with_benchmark do jobs.each do |job| @output.with_job(name: job.name) do - job.runnable_execs(@config.executables).each do |exec| - duration = run_benchmark(job, exec: exec) # no repeat support - @output.with_context(name: exec.name, executable: exec) do + job.runnable_contexts(@contexts).each do |context| + duration = run_benchmark(job, context: context) # no repeat support + @output.with_context(name: context.name, executable: context.executable, gems: context.gems) do @output.report(values: { METRIC => 1.0 / duration }, duration: duration, loop_count: 1) end end end end @@ -43,22 +45,22 @@ end private # @param [BenchmarkDriver::Runner::Ips::Job] job - loop_count is not nil - # @param [BenchmarkDriver::Config::Executable] exec + # @param [BenchmarkDriver::Context] context # @return [Float] duration - def run_benchmark(job, exec:) + def run_benchmark(job, context:) benchmark = BenchmarkScript.new( - prelude: job.prelude, + prelude: "#{context.prelude}\n#{job.prelude}", script: job.script, teardown: job.teardown, loop_count: job.loop_count, ) Tempfile.open(['benchmark_driver-', '.rb']) do |f| with_script(benchmark.render(result: f.path)) do |path| - execute(*exec.command, path) + execute(*context.executable.command, path) end Float(f.read) end end