a simple wrapper for Benchmark.bm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Benchmark(label_width) do |x| yield Benchmark(x, times) end end @bm = bm @iterations = iterations end args(method + ':') @bm(*args) do @iterations {block } end end end |
usage
1 2 3 4 5 6 7 |
compare 100_000 do |try| first, last = %w(Mislav Marohnic) try {[first, last](' ') } try {" " } try {first + ' ' + last } end |
output
1 2 3 4 |
user system total real join: 0.520000 0.070000 0.590000 ( 0.693261) interpolation: 0.490000 0.060000 0.550000 ( 0.631762) concatenation: 0.540000 0.060000 0.600000 ( 0.678998) |
Pastie