Ruby Performance

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;
    }
}

Hey,

It's faster, easier and more enjoyable to write better, cleaner, easier-to-understand code. :wink:

Julian.

···

On 13/08/2005, at 12:27 AM, 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;
    }
}

On Fri, 12 Aug 2005, Bradley Kite defenestrated me:

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 apologize in advance to any other Perl fans in advance)

  If you think that Ruby's language does not offer A LOT over Perl's
syntax, then you may want to go back to Perl. I came from the Perl
camp and I have not looked back (other than reading the crazy Exegesis
writings -- which makes me even happier to be using Ruby). I loved
Perl and used it for over a decade. I used to read people asking the
same performance questions you are asking now to the perl lists, but it
was about why you would use a scripting language over a real one(tm) :slight_smile:

  I think performance is largely a red herring. Most scripts I have
written have not even had a performance attribute. If it took 2 or 3
times longer it would not have mattered. Usually, anytime performance
did matter it was a matter of an external force...Like accessing a database.
I think few times I have written scripts which took 8+ hours to process
data. In all cases this was one time conversion and a 16 hour run time
would not have mattered.

  It sounds like Ruby's performance will get better with Rite (Ruby 2). Even
if it didn't I am more than happy with how it performs now. In other words
it does not seem slow when I work with it.

···

[micro-benchmark removed for brevity]

--
+ http://www.tc.umn.edu/~enebo +---- mailto:enebo@acm.org ----+

Thomas E Enebo, Protagonist | "Luck favors the prepared |
                             > mind." -Louis Pasteur |

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

Hello Bradley,

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).

Why ?

Python <-> Ruby:
Better consistent object modell, no indentation based language, but
Python is without doubt the hardest competitor. And its more or less
the same decision you must do when buying ice cream: Vanilla or
Chocolat ? Just a different flavour.

Perl <-> Ruby:
Perl is so ugly and difficult i don't want to compare it with ruby.
I doubt that it is possible to develop huge Perl programs where you
have a changing team of different programmers working on the same
code.

PHP <-> Ruby:
PHP is only a valid alternative for web development. And it is ugly
and unorthogonal.

TCL <-> Ruby:
Tcl is perfect for embedding it in apps and has a good infrastructure
(libraries, implementation) but the language is terrible unconvenient
for writing larger pure TCL programs.

···

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's

Well, non-idiomatic integer arithmatic might run twice as slowly :slight_smile:

Who cares? I certainly don't since the vast majority of my cycles are not spent in tight loops doing integer arithmetic. If it was I wouldn't be using Perl or Ruby (I'd probably be using Lisp :slight_smile:

The only performance figures that are important are whether tasks are fast enough in a particular context. Otherwise we'd all be writing assembler.

My pitch for Ruby to a Perl programmer would be:

- Perl 6 now! Many useful things that Perl 5 lacks and that Perl 6 will give you like a decent built in OO system, classes as proper objects, coroutines, simple block passing, etc. Ruby does now.

- Ruby has a simple threading system that actually works

- Ruby has the same TIMTOWTDI attitude as Perl so you'll feel at home, but has some better ways of doing some things that can make your code considerably less ugly.

- A more concise clearer syntax for many operations, which means you type less and your code is easier to maintain.

Cheers,

Adrian

···

On 12 Aug 2005, at 15:27, 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).

Wow, that C program is really fast, especially with the -O3 option.

Too bad there wasn't a way to hook your spiffy ultra-fast C loop into
Ruby. Wouldn't that be great? Some kind of "C" extension thing.

Then, your Ruby (and any language that can 'hook' C) is basically as fast
as C or even Assembler if you really get desperate.

Too bad that didn't exist. Oh well, I guess you'll have to keep testing
these loops and comparing them with Perl.

Zed A. Shaw

<snip>

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:

<snip>

···

(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

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

I think the performance issues will be fixed with the new virtual
machine they are developing, just look at this:

$ time ruby1.8 perf.rb

real 0m57.328s
user 0m52.766s
sys 0m0.178s

$ time ruby1.9 perf.rb

real 0m41.883s
user 0m40.081s
sys 0m0.085s

$ time ruby1.9 -rite perf.rb

real 0m2.528s
user 0m2.351s
sys 0m0.010s

ruby1.9 -rite means run ruby with the new VM,

Regards,

Paolo.

···

Il giorno ven, 12/08/2005 alle 23.27 +0900, Bradley Kite ha scritto:

(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;
    }
}

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.

That's even more simplistic than the benchmark programs on the Computer
Language Shootout :slight_smile:

Here's Ruby vs Perl
http://shootout.alioth.debian.org/benchmark.php?test=all&lang=ruby&sort=fullcpu

and here are the old Doug Bagley programs
http://shootout.alioth.debian.org/old/benchmark.php?test=all&lang=ruby&sort=fullcpu

Those idioms are around 21 seconds each in Ruby.

In perl, its 11 seconds to do this:

for (0..94967295)
{

}

The question is not so much about the run-time of a particular action,
but (in a web-based environment, for example) its more to do with
the number of concurrent users you can have without having to buy
more hardware.

···

--
Brad.

On 12/08/05, Robert Klemme <bob.news@gmx.net> wrote:

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

[snip]

Perl <-> Ruby:
Perl is so ugly and difficult i don't want to compare it with ruby.
I doubt that it is possible to develop huge Perl programs where you
have a changing team of different programmers working on the same
code.

[snip]

As somebody who does this on a regular basis I'd have to disagree :slight_smile:

Adrian

···

On 12 Aug 2005, at 16:23, Lothar Scholz wrote:

what do you mean by 'larger' (ie. # of lines of code)

i think one thing tcl has over the rest is tk. even for 'larger' programs.

i do all my gui prototyping in tcl/tk strictly for look and feel. then
i try to get the same result in ruby and invariably one gui api or
another problem shows up...

···

Lothar Scholz wrote on 8/12/2005 11:23 AM: > TCL <-> Ruby:

Tcl is perfect for embedding it in apps and has a good infrastructure
(libraries, implementation) but the language is terrible unconvenient
for writing larger pure TCL programs.

--
http://home.cogeco.ca/~tsummerfelt1
telnet://ventedspleen.dyndns.org

Hello Adrian,

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).

Well, non-idiomatic integer arithmatic might run twice as slowly :slight_smile:

Who cares? I certainly don't since the vast majority of my cycles are
not spent in tight loops doing integer arithmetic. If it was I
wouldn't be using Perl or Ruby (I'd probably be using Lisp :slight_smile:

The only performance figures that are important are whether tasks are
fast enough in a particular context. Otherwise we'd all be writing
assembler.

My pitch for Ruby to a Perl programmer would be:

- Perl 6 now! Many useful things that Perl 5 lacks and that Perl
6 will give you like a decent built in OO system, classes as proper
objects, coroutines, simple block passing, etc. Ruby does now.

Yes thats also going to piss me off. I thought they got a few paid
full time worker on the language (at least one or two from
activestate). But i see almost no progress in Perl 6.

Maybe they did a huge mistake when they dicided that all features and
programming paradigms currently known in the software world should be
supported by Perl6.

Sometimes less is more. Especially in language design.

···

On 12 Aug 2005, at 15:27, Bradley Kite wrote:

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's

zedshaw@zedshaw.com wrote:

Wow, that C program is really fast, especially with the -O3 option.

Too bad there wasn't a way to hook your spiffy ultra-fast C loop into
Ruby. Wouldn't that be great? Some kind of "C" extension thing.

Then, your Ruby (and any language that can 'hook' C) is basically as fast
as C or even Assembler if you really get desperate.

Too bad that didn't exist. Oh well, I guess you'll have to keep testing
these loops and comparing them with Perl.

Zed A. Shaw
http://www.zedshaw.com/

He could easily have done that with Tcl. Oh wait, you were being
sarcastic!

Robert

And, like Mr Kite's test, none of the Alioth shootout benchmarks are
worth squat.

-austin

···

On 8/15/05, Isaac Gouy <igouy@yahoo.com> wrote:

Bradley Kite wrote:
> 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.
That's even more simplistic than the benchmark programs on the Computer
Language Shootout :slight_smile:

Here's Ruby vs Perl
http://shootout.alioth.debian.org/benchmark.php?test=all&lang=ruby&sort=fullcpu

and here are the old Doug Bagley programs
http://shootout.alioth.debian.org/old/benchmark.php?test=all&lang=ruby&sort=fullcpu

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

The bottleneck is usually the database, tho... no? :slight_smile:

Read the ruby on rails book - and then you'll get some real-world-applications... take a look at basecamp - that's running with THOUSANDS of users... not sure how many concurrent... and it's all of one to two machines...

Julian.

···

On 13/08/2005, at 1:19 AM, Bradley Kite wrote:

Those idioms are around 21 seconds each in Ruby.

In perl, its 11 seconds to do this:

for (0..94967295)
{

}

The question is not so much about the run-time of a particular action,
but (in a web-based environment, for example) its more to do with
the number of concurrent users you can have without having to buy
more hardware.

--
Brad.

On 12/08/05, Robert Klemme <bob.news@gmx.net> wrote:

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

I'm not much of a Perl guy, so I don't know what TIMTOWTDI stands for.

This Is My T... O... Way To Do It?

Help a brother out :slight_smile:

Also, somebody mentioned slashdot -- does this mean we should bring up Nazis
too so we can kill the thread?

I'm sorry, I'm a little caffiened up today.

I do have a valid comment though: I was running ruby from a USB stick, and
it was horribly slow (2-3 minutes to run "ruby -v"). Installing onto my 2nd
logical partition (D:) helped, but it was still about 30 seconds to do the
same version check. Installing onto C: -- same physical drive as D: -- made
"ruby -v" practically instantaneous.

Unfortunately, yes I have Windows, so I'm sure that makes a difference.

···

On 8/12/05, Adrian Howard <adrianh@quietstars.com> wrote:

On 12 Aug 2005, at 16:23, Lothar Scholz wrote:
[snip]
> Perl <-> Ruby:
> Perl is so ugly and difficult i don't want to compare it with ruby.
> I doubt that it is possible to develop huge Perl programs where you
> have a changing team of different programmers working on the same
> code.
[snip]

As somebody who does this on a regular basis I'd have to disagree :slight_smile:

Adrian

--
Brock Weaver
http://www.circaware.com

Hello Adrian,

···

On 12 Aug 2005, at 16:23, Lothar Scholz wrote:
[snip]

Perl <-> Ruby:
Perl is so ugly and difficult i don't want to compare it with ruby.
I doubt that it is possible to develop huge Perl programs where you
have a changing team of different programmers working on the same
code.

[snip]

As somebody who does this on a regular basis I'd have to disagree :slight_smile:

Maybe your collegues are maybe better motivated, better paid and
better educated, then the onces i had to work with in the past
(on a very small project - in terms of LOC not of importance for the company).

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's

Hello tony,

Tcl is perfect for embedding it in apps and has a good infrastructure
(libraries, implementation) but the language is terrible unconvenient
for writing larger pure TCL programs.

what do you mean by 'larger' (ie. # of lines of code)

I mean complexer algorithms, more options and influces from the outside
world, more tighter connected modules.

Things where the OO and abstraction facilities of "real languages"
start shining. So instead large i should have written more complex.

i think one thing tcl has over the rest is tk. even for 'larger' programs.

i do all my gui prototyping in tcl/tk strictly for look and feel. then
i try to get the same result in ruby and invariably one gui api or
another problem shows up...

Yes, i loved TK and did a lot of TK/TCL programming in the past (as
you can find out when searching for my name in the comp.lang.tcl
newsgroup). And it is such a pitty that the TK evolution came to a
standstill for amost 10 years, with complete ignorance of changing
requirements, as i think technically TK is still the best toolkit out
there (binding events, matrix layout manager, canvas and text
widgets).

And this teached me a lession what can happen if too many people are
just saying: Its good enough for me. Sometimes when they realize that
this is not so anymore then it's too late to get back lost ground.

···

Lothar Scholz wrote on 8/12/2005 11:23 AM: >> TCL <-> Ruby:

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's

[snip]

> - Perl 6 now! Many useful things that Perl 5 lacks and that Perl
> 6 will give you like a decent built in OO system, classes as proper
> objects, coroutines, simple block passing, etc. Ruby does now.

Yes thats also going to piss me off. I thought they got a few paid
full time worker on the language (at least one or two from
activestate). But i see almost no progress in Perl 6.

I do. Parrot is an interesting platform for dynamic languages that's just getting to a reasonable state, and Pugs is just /storming/ along. You can play with large chunks of Perl 6 now.

Cheers,

Adrian

···

On 12 Aug 2005, at 17:36, Lothar Scholz wrote: