Skip to content

Instantly share code, notes, and snippets.

@miyohide
Created July 24, 2014 14:51
Show Gist options
  • Save miyohide/3ce4e2d466092496a346 to your computer and use it in GitHub Desktop.
Save miyohide/3ce4e2d466092496a346 to your computer and use it in GitHub Desktop.
method call benchmark
require "benchmark"
test_string = "test string"
n = 1_000_000
Benchmark.bmbm { |x|
x.report("normal") { n.times { test_string.length } }
x.report("send") { n.times { test_string.send(:length) } }
x.report("eval") { n.times { eval "test_string.length" } }
}
Rehearsal ------------------------------------------
normal 0.150000 0.000000 0.150000 ( 0.142557)
send 0.210000 0.000000 0.210000 ( 0.213529)
eval 15.360000 0.060000 15.420000 ( 15.443191)
-------------------------------- total: 15.780000sec
user system total real
normal 0.130000 0.000000 0.130000 ( 0.129682)
send 0.220000 0.000000 0.220000 ( 0.218464)
eval 15.310000 0.070000 15.380000 ( 15.405513)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment