Serious speed issues

Hi,
I’ve read in multiple places that JRuby is supposed to be faster than
standard ruby 1.8.7. I am seeing the exact opposite. I would love to
find the problem.
My setup
-Ubuntu 11.04
-Open JDK “java version "1.6.0_22"”
-JRuby 1.6.2 downloaded from jruby.org and unzipped
-Ruby 1.8.7 (patchlevel 302)

I am running a simple script that calculates the n’th number in the
fibonacci sequence.

-----------Code (fib.rb)-----------
def calcFibN(num)
fib_array = [0,1]
(num-2).times do |i|
fib_array << (fib_array[i] + fib_array[i+1])
end
puts fib_array.join(", ")
end
calcFibN(ARGV[0].to_i)
-----------End (fib.rb)-----------

what I see
time ruby fib.rb 30
real: 0m0.018s
time jruby fib.rb 30
real: 0m1.925s

I also tried jruby’s benchmark mode and it returned 420ms, which is
still much more than what ‘time ruby fib.rb 30’ returned

This performace is not only slower than ruby, it’s practically unusable.
What have I done wrong?

Thank you all :slight_smile:
Whit

-----------Edit-------------
For further info. I have a very similar java app written and I get
time java Fib 30
real: 0m0.125s

and a copy written in gnu c99
time ./fib 30
real: 0m0.005ms

you need to take the startup time out of the equation,
try a larger number

cheer,
Luis

Luis Landeiro ribeiro wrote in post #1001569:

you need to take the startup time out of the equation,
try a larger number

cheer,
Luis

I thought this might be an issue, but even factoring out warm up time
there is a significant speed difference. I see largely varrying numbers
with startup time, but on average the difference between jruby fib.rb 30
and jruby fib.rb 100 is 30ms while ruby fib.rb 30 vs ruby fib.rb 100
only varries by 1ms.

On May 27, 2011, at 12:22 PM, Hidden Premise wrote:

and jruby fib.rb 100 is 30ms while ruby fib.rb 30 vs ruby fib.rb 100
only varries by 1ms.

This is a common issue when folks compare MRI to JRuby to Rubinius to
MacRuby, etc.

You aren’t going to get very interesting benchmark numbers on anything
that runs in under a second. I recommend you benchmark something that
takes at least 5 seconds to run. It will give the JIT time to warm up
and optimize the code. Not much optimization can happen on code that
completes in 400ms.

cr

yes try something like

300.times {

calcFibN(ARGV[0].to_i)
}

Also try the --server option for the server VM.
Cheers!
-roger-