lib/benchmark/runner/exec.rb in benchmark_driver-0.4.3 vs lib/benchmark/runner/exec.rb in benchmark_driver-0.4.4

- old
+ new

@@ -65,11 +65,11 @@ # @param [Benchmark::Driver::Configuration::Executable] executable def run_benchmark(job, executable) fields = @output.class::REQUIRED_FIELDS if fields == [:real] Benchmark::Driver::RepeatableRunner.new(job).run( - runner: build_runner(executable.path), + runner: build_runner(executable.command), repeat_count: @options.repeat_count, ).tap do |result| if result.real < 0 raise Benchmark::Driver::ExecutionTimeTooShort.new(job, result.iterations) end @@ -77,11 +77,11 @@ elsif fields == [:max_rss] # TODO: we can also capture other metrics with /usr/bin/time raise '/usr/bin/time is not available' unless File.exist?('/usr/bin/time') script = BenchmarkScript.new(job.prelude, job.script).full_script(job.loop_count) with_file(script) do |script_path| - out = Bundler.with_clean_env { IO.popen(['/usr/bin/time', executable.path, script_path], err: [:child, :out], &:read) } + out = Bundler.with_clean_env { IO.popen(['/usr/bin/time', *executable.command, script_path], err: [:child, :out], &:read) } 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(out) raise "Unexpected format given from /usr/bin/time:\n#{out}" unless match_data[:maxresident] Benchmark::Driver::BenchmarkResult.new(job).tap do |result| result.max_rss = Integer(match_data[:maxresident]) @@ -131,15 +131,15 @@ ip100ms end # @param [String] path - Path to Ruby executable # @return [Proc] - Lambda to run benchmark - def build_runner(path = RbConfig.ruby) + def build_runner(command = [RbConfig.ruby]) lambda do |job, times| benchmark = BenchmarkScript.new(job.prelude, job.script) - measure_seconds(path, benchmark.full_script(times)) - - measure_seconds(path, benchmark.overhead_script(times)) + measure_seconds(command, benchmark.full_script(times)) - + measure_seconds(command, benchmark.overhead_script(times)) end end def with_file(content, &block) Tempfile.create(File.basename(__FILE__)) do |f| @@ -147,12 +147,12 @@ f.close block.call(f.path) end end - def measure_seconds(ruby, script) + def measure_seconds(command, script) with_file(script) do |path| - cmd = [ruby, path].shelljoin + cmd = [*command, path].shelljoin Bundler.with_clean_env do before = Benchmark::Driver::Time.now system(cmd, out: File::NULL) after = Benchmark::Driver::Time.now