Permalink
Browse files

Order the benchmark results by column name rather than position.

Previously, benchmarking

  one   { foo }
  three { baz }
  two   { bar }

would display the time for one first, three second, and two third,
even if the column names were ordered :one, :two, :three.
  • Loading branch information...
1 parent 0236076 commit 73abbc232b435a162698b8925818bff218c78bf2 @nex3 nex3 committed May 6, 2008
Showing with 6 additions and 6 deletions.
  1. +6 −6 lib/benchwarmer.rb
View
@@ -64,8 +64,8 @@ def run(&blk)
print "%#{@group_max}s" % name
# Actually run the benchmarks
- procs.each_with_index do |proc, i|
- head = @columns[@columns.order[i]]
+ procs.each_with_index do |(column, proc), i|
+ head = @columns[column]
bench = Benchmark.measure { @times.times(&proc)}
print (" %#{head.size >= 5 ? head.size : 5}.2f |" % bench.real)
end
@@ -98,7 +98,7 @@ def group(str, &blk)
def report(str, &blk)
@groups ||= Dictionary.new {|h,k| h[k] = Dictionary.new}
if !@columns || @columns.size == 1
- @groups[@current_group || ""][str] = [blk]
+ @groups[@current_group || ""][str] = {(@columns && @columns.order[0]) || :results => blk}
else
report = GroupReport.new(@columns.keys)
report.instance_eval(&blk)
@@ -120,12 +120,12 @@ def initialize(cols)
cols.each do |col|
new_self.class_eval <<-RUBY
def #{col}(&blk)
- @runs ||= []
- @runs << blk
+ @runs ||= {}
+ @runs[#{col.to_sym.inspect}] = blk
end
RUBY
end
end
end
-end
+end

0 comments on commit 73abbc2

Please sign in to comment.