Benchmark reflection : Benchmark « Development « Ruby






Benchmark reflection


require 'benchmark' 

include Benchmark 
test = "this is a test" 
m = test.method(:length) 
n = 100000 
bm(12) {|x| 
    x.report("call") { n.times { m.call } } 
    x.report("send") { n.times { test.send(:length) } } 
    x.report("eval") { n.times { eval "test.length" } } 
} 

 








Related examples in the same category

1.Simple Benchmarking
2.Because measure accepts code blocks, you can make it as elaborate
3.Benchmark includes a way to make completing multiple tests more convenient.
4.Benchmark inline c