[MacRuby-devel] Speed

John Shea johnmacshea at gmail.com
Mon Nov 23 00:20:28 PST 2009


Hi Uliano,

The way I get the JIT to preprocess your fib code is simply to call the method once. For example I wrapped your code in a class (not that I am saying that it is necessary to do this - its just the first thing i tried and it worked) and then.

(for example)
afib.fib_iter(sum,10)

and then time test with afib.fib_iter(sum,4_000_000)

I think you have to also keep in mind that the method dispatch in macruby is a work in progress and that method dispatch time is always going to be different between different ruby implementations.
In your code for example passing a block and dispatching that block always with yield could be a performance stopper - when i rewrote your original  code to not have these yield calls I got much improved performance:

#command line: ruby or  macruby fib.rb

#ruby 1.8.7
recursive
sum = 
4613732
time = 
18.795026
iterative
sum = 
4613732
time = 
3.0e-05


#macruby beta 0.5-2
#no pre compile
recursive
sum = 
4613732
time = 
0.585983
iterative
sum = 
4613732
time = 
0.007148

#macruby beta 0.5-2
#run it once first
recursive
sum = 
4613732
time = 
0.591092
iterative
sum = 
4613732
time = 
0.002592


#macruby beta 0.5-2
#run it once first and using code without yields.

recursive
sum = 
4613732
time = 
0.586312
iterative
sum = 
4613732
time = 
3.0e-06

hope that helps,
John

On Nov 23, 2009, at 8:30 , Uliano Guerrini wrote:

> Thank you all
> 
> I didn't realize that JIT in macruby is compiling on the fly the code piece a piece (I thought that a source file was the compilation unit) and so JIT time to compile the block was inside my time metrics
> 
> I re-run the test looping many times and the results are speaking for themselfs:
> 
> uliano$ macruby fib.rb 
> sum of even Fibonacci less than 4000000 = 4613732
> time = 0.637182
> uliano$ /usr/bin/ruby fib.rb 
> sum of even Fibonacci less than 4000000 = 4613732
> time = 4.710929
> uliano$ ruby fib.rb                               # this is Ruby 1.9.1 from macports
> sum of even Fibonacci less than 4000000 = 4613732
> time = 0.660384
> uliano$ macrubyc -o fib fib.rb
> uliano$ ./fib
> sum of even Fibonacci less than 4000000 = 4613732
> time = 0.61873
> 
> 
> 
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel



More information about the MacRuby-devel mailing list