On Wed, 12 Jul 2006 20:11:53 +0200, Stephan Wehner  
<stephanwehner / gmail.com> wrote:

> I ran this simple ruby script
>
> max = 5000
> z = 0
> 1.upto(max) do |x|
>   1.upto(max) do |y|
>     z = (x+y-z) % 32000
>   end
> end
> puts 'Got z = ' + z.to_s
>
> Results on an Intel Pentium 4 CPU 3.00GHz.
>
> 33 seconds -- ruby 1.8.4 (2005-12-24) [i386-linux]
>
> 20 seconds -- ruby 1.9.0 (2006-07-07) [i686-linux]
>
> 10 seconds -- ruby-yarv / ruby 2.0.0 (Base: Ruby 1.9.0 2006-04-08)
> [i686-linux]
> YARVCore 0.4.0 Rev: 510 (2006-07-06) [opts: ]
>
> 5 seconds -- ruby-yarv / ruby 2.0.0 (Base: Ruby 1.9.0 2006-04-08)
> [i686-linux]
> YARVCore 0.4.1 Rev: 519 (2006-07-12) [opts: [direct threaded code]
> [inline method cache] ]

Here are the results with Ruby2CExtension (HEAD revision, not 0.1.0) on a  
Pentium M 1.5 GHz:

$ ruby -v
ruby 1.8.4 (2005-12-24) [i686-linux]

$ time ruby test.rb
Got z = 20000

real    0m31.163s
user    0m30.829s
sys     0m0.056s

$ rb2cx test.rb

$ time ruby -r test.so -e ""
Got z = 20000

real    0m11.980s
user    0m11.824s
sys     0m0.021s


And it is even faster with while loops:

$ cat test_while.rb
max = 5000
z = x = 0
while (x+=1) <= max
   y = 0
   while (y+=1) <= max
     z = (x+y-z) % 32000
   end
end
puts 'Got z = ' + z.to_s

$ time ruby test_while.rb
Got z = 20000

real    0m35.067s
user    0m34.705s
sys     0m0.059s

$ rb2cx test_while.rb

$ time ruby -r test_while.so -e ""
Got z = 20000

real    0m5.075s
user    0m5.019s
sys     0m0.015s


Dominik