Mega Code Archive

 
Categories / Ruby / Development
 

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" } }  }