Eval method seems to be slower than mri


#1

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?


#2

It is fairly well know by us that eval is slower for us. I believe we
have a bug open on this somewhere.

We will be able to make some progress on this in the future since we
are splitting off our IDE-support in the parser, but we will probably
never parse (therefore run) as fast as MRI (I should not say ‘never’
:slight_smile: ).

For what it is worth, Ruby1.9 is not very fast at eval either since it
needs to compile to YARV bytecode before running.

-Tom

On Thu, Dec 4, 2008 at 5:46 PM, Khaled al Habache removed_email_address@domain.invalid
wrote:

x.report(“send”) { n.times { test.send(:length) } }
eval 0.350000 0.050000 0.400000 ( 0.392843)
eval 2.731000 0.000000 2.731000 ( 2.731181)


Blog: http://www.bloglines.com/blog/ThomasEEnebo
Email: removed_email_address@domain.invalid , removed_email_address@domain.invalid


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email