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

- old
+ new

@@ -16,13 +16,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) @@ -38,15 +40,15 @@ end @output.with_benchmark do jobs.each do |job| @output.with_job(name: job.name) do - job.runnable_execs(@config.executables).each do |exec| + job.runnable_contexts(@contexts).each do |context| value = BenchmarkDriver::Repeater.with_repeat(config: @config, larger_better: false) do - run_benchmark(job, exec: exec) + run_benchmark(job, context: context) end - @output.with_context(name: exec.name, executable: exec) do + @output.with_context(name: context.name, executable: context.executable, gems: context.gems) do @output.report(values: { METRIC => value }, loop_count: job.loop_count) end end end end @@ -54,21 +56,21 @@ end private # @param [BenchmarkDriver::Runner::Ips::Job] job - loop_count is not nil - # @param [BenchmarkDriver::Config::Executable] exec + # @param [BenchmarkDriver::Context] context # @return [BenchmarkDriver::Metrics] - 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, ) output = with_script(benchmark.render) do |path| - execute('/usr/bin/time', *exec.command, path) + execute('/usr/bin/time', *context.executable.command, path) end match_data = /^(?<user>\d+.\d+)user\s+(?<system>\d+.\d+)system\s+(?<elapsed1>\d+):(?<elapsed2>\d+.\d+)elapsed.+\([^\s]+\s+(?<maxresident>\d+)maxresident\)k$/.match(output) raise "Unexpected format given from /usr/bin/time:\n#{out}" unless match_data[:maxresident]