GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Prettier Benchmarking for Ruby
Clone URL: git://github.com/wycats/benchwarmer.git
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.
nex3 (author)
Mon May 05 17:02:25 -0700 2008
commit  73abbc232b435a162698b8925818bff218c78bf2
tree    6ad1b85a37ea985b1da76231a42f261aabafe20b
parent  02360768f5dfd5ea6f438c48247fa681ba672dfc
...
64
65
66
67
68
 
 
69
70
71
...
98
99
100
101
 
102
103
104
...
120
121
122
123
124
 
 
125
126
127
128
129
130
131
132
 
...
64
65
66
 
 
67
68
69
70
71
...
98
99
100
 
101
102
103
104
...
120
121
122
 
 
123
124
125
126
127
128
129
130
 
131
132
0
@@ -64,8 +64,8 @@ module Benchmark
0
           print "%#{@group_max}s" % name
0
           
0
           # Actually run the benchmarks
0
- procs.each_with_index do |proc, i|
0
- head = @columns[@columns.order[i]]
0
+ procs.each_with_index do |(column, proc), i|
0
+ head = @columns[column]
0
             bench = Benchmark.measure { @times.times(&proc)}
0
             print (" %#{head.size >= 5 ? head.size : 5}.2f |" % bench.real)
0
           end
0
@@ -98,7 +98,7 @@ module Benchmark
0
     def report(str, &blk)
0
       @groups ||= Dictionary.new {|h,k| h[k] = Dictionary.new}
0
       if !@columns || @columns.size == 1
0
- @groups[@current_group || ""][str] = [blk]
0
+ @groups[@current_group || ""][str] = {(@columns && @columns.order[0]) || :results => blk}
0
       else
0
         report = GroupReport.new(@columns.keys)
0
         report.instance_eval(&blk)
0
@@ -120,12 +120,12 @@ module Benchmark
0
       cols.each do |col|
0
         new_self.class_eval <<-RUBY
0
           def #{col}(&blk)
0
- @runs ||= []
0
- @runs << blk
0
+ @runs ||= {}
0
+ @runs[#{col.to_sym.inspect}] = blk
0
           end
0
         RUBY
0
       end
0
     end
0
   end
0
   
0
-end
0
\ No newline at end of file
0
+end

Comments

    No one has commented yet.