> Lett Kent Sibilev <ksibilev / bellsouth.net>
> Aihe: Re: Benchmark Mono - Ruby
> 
> 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

The kind of magnitude in difference that the OP cited is certainly
something to worry about, performance-wise. A couple seconds here or
there in large operations is OK, of course. I'm not going to argue
against it if someone comes up with a Ruby implementation that runs
as fast as native C, but in general Ruby's performance is well above
adequate. If one finds a serious bottleneck, it may first be possible
to be solved simply by rewriting the Ruby. That failing, dropping 
down to Inline/Ruby2C/C will certainly remove the problem--and the 
two former with relative ease since one doesn't have to actually 
write C. 

Here Mr. Sibilev succintly isolated the bit of code that was assessed
to be a candidate for lower-level implementation for performance 
enhancement and enhanced its performance.

> Cheers,
> Kent.

E
 
> 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
> >
> 
> 
>