Consider this 'tuning':

$ cat t.rb
require 'ruby_to_c'

module Inline
   class Ruby < Inline::C
     def initialize(mod)
       super
     end

     def optimize(meth)
       src = RubyToC.translate(@mod, meth)
       @mod.class_eval "alias :#{meth}_slow :#{meth}"
       @mod.class_eval "remove_method :#{meth}"
       c src
     end
   end
end

class Test
   def run
     d=0
     1000000000.downto(1) {
       d = d + 1
     }
     return d
   end

   inline(:Ruby) do |builder|
     builder.optimize :run
   end
end

puts Test.new.run

$ time ruby t.rb
1000000000

real    0m3.118s
user    0m2.670s
sys     0m0.050s

$ cat t.cs
using System;

class Bench {
   public static void Main() {
     double d = 0;

     for (int i = 0; i < 1000000000; i++) {
       d = d + i;
     }

     Console.WriteLine(d);
   }
}

$ mcs t.cs
Compilation succeeded

$ time mono t.exe
4.99999999067109E+17

real    0m37.692s
user    0m34.540s
sys     0m0.040s


Cheers,
Kent.

On Feb 5, 2005, at 10:05 PM, Michael Gebhart wrote:

> Hi,
>
> because of my interest in mono and ruby I have done a small benchmark.
> These are the results:
>
> Mono Code:
>
> using System;
>
> class Bench {
>   public static void Main() {
>     double d = 0;
>
>     for (int i = 0; i < 1000000000; i++) {
>       d = d + i;
>     }
>
>     Console.WriteLine(d);
>   }
>
> Needs 10.8 Seconds.
>
>
> In Ruby:
>
> d=0
> 1000000000.times {
>   d = d + 1
> }
>
> puts d
>
>
> Needs: 8 minutes and 20 seconds.
>
>
> Does not look very good :( Is there a possibility to tune my 
> ruby-program,
> to be as fast as mono?
>
> Greetings
>
> Mike
>