hi, i was trying this simple test on both ruby mri 1.8.7 and jruby 1.5
to
benchmark the different ways of dynamic method calling in ruby.
have a look on the test :
require “benchmark” # from the Ruby Application Archive include
Benchmark
test = “Stormy Weather”
m = test.method(:length)
n = 100000
Benchmark.bmbm {|x|
x.report(“call”) { n.times { m.call } }
x.report(“send”) { n.times { test.send(:length) } }
x.report(“eval”) { n.times { eval “test.length” } }
}
and here is my console output :
khelll@khelll-laptop:~$ ruby projects/rubytest/eval.rb
Rehearsal ----------------------------------------
call 0.040000 0.030000 0.070000 ( 0.068623)
send 0.060000 0.010000 0.070000 ( 0.076176)
eval 0.350000 0.050000 0.400000 ( 0.392843)
------------------------------- total: 0.540000sec
user system total real
call 0.060000 0.010000 0.070000 ( 0.073063)
send 0.060000 0.020000 0.080000 ( 0.078077)
eval 0.370000 0.020000 0.390000 ( 0.393576)
khelll@khelll-laptop:~$ jruby projects/rubytest/eval.rb
Rehearsal ----------------------------------------
call 0.076000 0.000000 0.076000 ( 0.076363)
send 0.054000 0.000000 0.054000 ( 0.053325)
eval 2.731000 0.000000 2.731000 ( 2.731181)
------------------------------- total: 2.861000sec
user system total real
call 0.023000 0.000000 0.023000 ( 0.023475)
send 0.041000 0.000000 0.041000 ( 0.041561)
eval 2.646000 0.000000 2.646000 ( 2.645752)
khelll@khelll-laptop:~$
What do u think?