From: Robert Klemme Date: 2005-08-13T00:06:20+09:00 Subject: Re: Ruby Performance Bradley Kite wrote: > Hi all, > > I'm a relatively new Ruby programmer, I am curious as to what Ruby is > trying to achieve that other scripting languages do not already offer > (Apart from the syntactic differences of yet another scripting > language, that is). > The reason I ask is that it must offer something that is worth a lot > considering it runs twice as slowly as Perl (see below). > > I was also interested in comparing the performance of Ruby against > something like Perl, and (although this test is VERY simple) thought > that I'd benchmark > a simple counter in both Ruby and Perl. The number that it counts to > is arbitrary, > I started with 4294967296 and kept reducing it because I got bored of > waiting). Code is provided below. > > Any way, on a 3Ghz P4 CPU, I got the following results: > > Perl: > real 0m24.569s > user 0m24.499s > sys 0m0.068s > > Ruby: > real 0m57.218s > user 0m57.108s > sys 0m0.109s > > (Just out of interest I did it in C as well): > > (Average Run, non-optimised) > real 0m0.142s > user 0m0.136s > sys 0m0.005s > > (Average Run, -O3 optimisations): > real 0m0.074s > user 0m0.070s > sys 0m0.004s > > ################################## > > #!/usr/bin/perl > my $num = 0; > > while ($num < 94967295) > { > $num += 1; > } > > ############### > > #!/usr/bin/ruby > num = 0 > > while num < 94967295 do > num += 1 > end > > ############### > > int main() > { > int counter = 0; > > while (counter < 94967295) > { > counter += 1; > } > } Just out of curiosity: did you also benchmark these Ruby idioms (which I regard more typical): 94967295.times do end for i in 0..94967295 do end 0.upto 94967295 do end Kind regards robert