Ruby Performance

B

Bradley Kite

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 (Apar=
t
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 consid=
ering
it runs twice as slowly as Perl (see below).

I was also interested in comparing the performance of Ruby against somethin=
g
like Perl, and (although this test is VERY simple) thought that I'd benchma=
rk
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 waiti=
ng).
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 =3D 0;

while ($num < 94967295)
{
$num +=3D 1;
}

###############

#!/usr/bin/ruby
num =3D 0

while num < 94967295 do
num +=3D 1
end

###############

int main()
{
int counter =3D 0;

while (counter < 94967295)
{
counter +=3D 1;
}
}
 
J

Julian Leviston

Hey,

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

Julian.
 
T

Thomas E Enebo

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

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]
 
R

Robert Klemme

Bradley said:
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
 
B

Bradley Kite

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

Lothar Scholz

Hello Bradley,

BK> Hi all,

BK> I'm a relatively new Ruby programmer, I am curious as to what Ruby is
BK> trying to achieve that other scripting languages do not already offer (Apart
BK> 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.
 
J

Julian Leviston

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

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

Adrian Howard

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

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

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
 
B

Bradley Kite

Compared with - say - slashdot?

The bottleneck is usually the database, tho... no? :)
=20
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...
=20
Julian.
=20
On 13/08/2005, at 1:19 AM, Bradley Kite wrote:
=20
=20
=20
 
A

Adrian Howard

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

Adrian
 
A

Adrian Howard

Compared with - say - slashdot?
[snip]

I'm sure with sufficient effort somebody could run Amazon with a
large parallel group of highly trained stoats. Who cares :)

There are large web sites built with Java, Perl, Ruby, C++, Lisp, C#,
PHP and god knows how many other languages. PHP and Perl didn't build
their market share because they were /faster/ - they built it because
they were /better/ (for certain definitions of "better").

Perl's big advantage is that it's a nice flexible language that
enable you to build applications quickly and reliably (despite what
some people say :)

Ruby's advantage over Perl 5 is that it does some stuff that Perl 5
can't do, and makes much of the stuff it can do easier (in certain
areas anyway).

Compare the simplicity of overriding some_method= with messing with
lvalue subs and tied variables to get the same affect in Perl 5. Some
things are simpler and, when it comes to writing and maintaining
code, simpler is better.

Adrian
 
B

Brock Weaver

------=_Part_3091_9365412.1123862284135
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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


Also, somebody mentioned slashdot -- does this mean we should bring up Nazi=
s=20
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=
=20
it was horribly slow (2-3 minutes to run "ruby -v"). Installing onto my 2nd=
=20
logical partition (D:) helped, but it was still about 30 seconds to do the=
=20
same version check. Installing onto C: -- same physical drive as D: -- made=
=20
"ruby -v" practically instantaneous.

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


=20
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]
=20
As somebody who does this on a regular basis I'd have to disagree :)
=20
Adrian
=20
=20
=20


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

------=_Part_3091_9365412.1123862284135--
 
J

jm

TIMTOWTDI - there is more than one way to do it


I'm not much of a Perl guy, so I don't know what TIMTOWTDI stands for.
=20
This Is My T... O... Way To Do It?
=20
Help a brother out :)
=20
=20
Also, somebody mentioned slashdot -- does this mean we should bring up Na= zis
too so we can kill the thread?
=20
I'm sorry, I'm a little caffiened up today.
=20
I do have a valid comment though: I was running ruby from a USB stick, an= d
it was horribly slow (2-3 minutes to run "ruby -v"). Installing onto my 2= nd
logical partition (D:) helped, but it was still about 30 seconds to do th= e
same version check. Installing onto C: -- same physical drive as D: -- ma= de
"ruby -v" practically instantaneous.
=20
Unfortunately, yes I have Windows, so I'm sure that makes a difference.
=20
=20
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 :)

Adrian
=20
=20
 
B

Brian Schröder

On 12 Aug 2005, at 16:39, Bradley Kite wrote:
=20
Compared with - say - slashdot?
[snip]
=20
I'm sure with sufficient effort somebody could run Amazon with a
large parallel group of highly trained stoats. Who cares :)

That reminds me of the pc technologie:

http://www.google.com/technology/pigeonrank.html

regards,

Brian
=20
There are large web sites built with Java, Perl, Ruby, C++, Lisp, C#,
PHP and god knows how many other languages. PHP and Perl didn't build
their market share because they were /faster/ - they built it because
they were /better/ (for certain definitions of "better").
=20
Perl's big advantage is that it's a nice flexible language that
enable you to build applications quickly and reliably (despite what
some people say :)
=20
Ruby's advantage over Perl 5 is that it does some stuff that Perl 5
can't do, and makes much of the stuff it can do easier (in certain
areas anyway).
=20
Compare the simplicity of overriding some_method=3D with messing with
lvalue subs and tied variables to get the same affect in Perl 5. Some
things are simpler and, when it comes to writing and maintaining
code, simpler is better.
=20
Adrian
=20
=20


--=20
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/
 
T

tony summerfelt

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.

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

Lothar Scholz

Hello Adrian,


AH> Well, non-idiomatic integer arithmatic might run twice as slowly :)

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

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

AH> My pitch for Ruby to a Perl programmer would be:

AH> - Perl 6 now! Many useful things that Perl 5 lacks and that Perl
AH> 6 will give you like a decent built in OO system, classes as proper
AH> 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.
 
L

Lothar Scholz

Hello Adrian,

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

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

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

Lothar Scholz

Hello Adrian,

AH> Perl's big advantage is that it's a nice flexible language that
AH> enable you to build applications quickly and reliably (despite what
AH> some people say :)

I think it's biggest advantage is that is is so long out there, that
it just has its market share. And it won that market share via the
sysadmins - for which is was always designed from the beginning.
 
C

Chris Martin

=20
I'm sure with sufficient effort somebody could run Amazon with a
large parallel group of highly trained stoats. Who cares :)
=20
There are large web sites built with Java, Perl, Ruby, C++, Lisp, C#,
PHP and god knows how many other languages. PHP and Perl didn't build
their market share because they were /faster/ - they built it because
they were /better/ (for certain definitions of "better").

Very true.
Those definitions of better can vary greatly depending on what you're
coding too.

Thanks to Rails, I think we'll see Ruby's market share (on the web)
increase drastically in time to come.

IMO Ruby (on rails) offers much faster development, and near instant
productivity. That is a great achievement that no other
language/framework can come close to.

As always, it's a matter of "the right tool for the job".
Like perl, ruby can do many jobs.

Also (IMO) ruby offers a nice bridge to all forms of programming (cli,
gui, web), and as many have said before.... it's just a joy to work
in! :)

--=20
Chris Martin
Web Developer
Open Source & Web Standards Advocate
http://www.chriscodes.com/
 
L

Lothar Scholz

Hello tony,

ts> Lothar Scholz wrote on 8/12/2005 11:23 AM:

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

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

ts> i do all my gui prototyping in tcl/tk strictly for look and feel. then
ts> i try to get the same result in ruby and invariably one gui api or
ts> 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top