diff --git a/ChangeLog b/ChangeLog index bba4a953a9..19e674a42a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jul 7 06:46:12 2011 Eric Hodel + + * benchmark/driver.rb: Add difference column to report that averages + across all runs of a benchmark. [Ruby 1.9 - Feature #4982] + Thu Jul 7 06:19:38 2011 Eric Hodel * lib/rubygems.rb: Reduce requires to improve `make benchmark`. diff --git a/benchmark/driver.rb b/benchmark/driver.rb index c38c4fb3da..7dab292a15 100644 --- a/benchmark/driver.rb +++ b/benchmark/driver.rb @@ -90,6 +90,10 @@ class BenchmarkDriver end end + def average results + results.inject(:+) / results.length + end + def show_results output @@ -109,7 +113,10 @@ class BenchmarkDriver output "minimum results in each #{@repeat} measurements." end - output "name\t#{@execs.map{|(e, v)| v}.join("\t")}" + difference = "\taverage difference" if @execs.length == 2 + total_difference = 0 + + output "name\t#{@execs.map{|(e, v)| v}.join("\t")}#{difference}" @results.each{|v, result| rets = [] s = nil @@ -129,8 +136,20 @@ class BenchmarkDriver end rets << sprintf("%.3f", r) } + + if difference + diff = average(result.last) - average(result.first) + total_difference += diff + rets << sprintf("%.3f", diff) + end + output "#{v}#{s}\t#{rets.join("\t")}" } + + if difference and @verbose + output '-----------------------------------------------------------' + output "average total difference is #{total_difference}" + end end def files