lib/benchmark/runner/exec.rb in benchmark_driver-0.4.1 vs lib/benchmark/runner/exec.rb in benchmark_driver-0.4.2
- old
+ new
@@ -1,5 +1,6 @@
+require 'bundler'
require 'tempfile'
require 'shellwords'
require 'benchmark/driver/benchmark_result'
require 'benchmark/driver/duration_runner'
require 'benchmark/driver/repeatable_runner'
@@ -76,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 = IO.popen(['/usr/bin/time', executable.path, script_path], err: [:child, :out], &:read)
+ out = Bundler.with_clean_env { IO.popen(['/usr/bin/time', executable.path, 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])
@@ -150,14 +151,16 @@
def measure_seconds(ruby, script)
with_file(script) do |path|
cmd = [ruby, path].shelljoin
- before = Benchmark::Driver::Time.now
- system(cmd, out: File::NULL)
- after = Benchmark::Driver::Time.now
+ Bundler.with_clean_env do
+ before = Benchmark::Driver::Time.now
+ system(cmd, out: File::NULL)
+ after = Benchmark::Driver::Time.now
- after.to_f - before.to_f
+ after.to_f - before.to_f
+ end
end
end
class BenchmarkScript < Struct.new(:prelude, :script)
BATCH_SIZE = 1000