lib/benchmark_driver/output/compare.rb in benchmark_driver-0.16.4 vs lib/benchmark_driver/output/compare.rb in benchmark_driver-0.16.5

- old
+ new

@@ -97,11 +97,11 @@ # Show pretty seconds / clocks too. As it takes long width, it's shown only with a single executable. if @job_results.size == 1 result = @job_results.first sec = result.duration iter = result.loop_count - if File.exist?('/proc/cpuinfo') && (clks = estimate_clock(sec, iter)) < 1_000 + if File.exist?('/proc/cpuinfo') && (clks = estimate_clock(sec, iter)) && (clks < 1_000) $stdout.print(" (#{pretty_sec(sec, iter)}/i, #{clks}clocks/i)") else $stdout.print(" (#{pretty_sec(sec, iter)}/i)") end end @@ -154,10 +154,14 @@ "#{'%3.2f' % (r * 1_000_000_000).to_f}ns" end end def estimate_clock sec, iter - hz = File.read('/proc/cpuinfo').scan(/cpu MHz\s+:\s+([\d\.]+)/){|(f)| break hz = Rational(f.to_f) * 1_000_000} + hz = nil + + File.read('/proc/cpuinfo').scan(/cpu MHz\s+:\s+([\d\.]+)/){|(f)| break hz = Rational(f.to_f) * 1_000_000} + return unless hz + r = Rational(sec, iter) Integer(r/(1/hz)) end def compare_jobs