lib/benchmark/output/ips.rb in benchmark_driver-0.8.4 vs lib/benchmark/output/ips.rb in benchmark_driver-0.8.5
- old
+ new
@@ -59,10 +59,19 @@
if @row_results.size == @executables.size
$stdout.print("i/s - #{humanize(result.iterations)} in")
@row_results.each do |r|
$stdout.print(" %3.6fs" % r.real)
end
+ if @row_results.size == 1
+ sec = @row_results[0].real
+ iter = result.iterations
+ if File.exist?('/proc/cpuinfo') && (clks = estimate_clock(sec, iter)) < 1_000
+ $stdout.print(" (#{pretty_sec(sec, iter)}/i, #{clks}clocks/i)")
+ else
+ $stdout.print(" (#{pretty_sec(sec, iter)}/i)")
+ end
+ end
$stdout.puts
end
@name_by_result[result] = executable.name
end
@@ -79,17 +88,37 @@
scale = (Math.log10(value) / 3).to_i
suffix =
case scale
when 1; 'k'
when 2; 'M'
- when 3; 'B'
+ when 3; 'G'
when 4; 'T'
when 5; 'Q'
else # < 1000 or > 10^15, no scale or suffix
scale = 0
' '
end
"%#{width}.3f#{suffix}" % (value.to_f / (1000 ** scale))
+ end
+
+ def pretty_sec sec, iter
+ r = Rational(sec, iter)
+ case
+ when r >= 1
+ "#{'%3.2f' % r.to_f}s"
+ when r >= 1/1000r
+ "#{'%3.2f' % (r * 1_000).to_f}ms"
+ when r >= 1/1000_000r
+ "#{'%3.2f' % (r * 1_000_000).to_f}us"
+ else
+ "#{'%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}
+ r = Rational(sec, iter)
+ Integer(r/(1/hz))
end
def compare
$stdout.puts("\nComparison:")
results = @results.sort_by { |r| -r.ips }