Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1

Reply
Thread Tools

This is why Ruby 1.8.6 can never be made to run anywhere near as fast as Python 2.5.1

 
 
Ruby Maniac
Guest
Posts: n/a
 
      09-24-2007
I welcome any corrections anyone might be able to make since I am new
to Ruby with less than 3 months experience under my belt.

Ruby 1.8.6 is an interpreted langauge that does not have a byte-code
driven VM at this time.

Python 2.5.1 is an interpreted language that does have a byte-code
driven VM.

I have been able to make Ruby code run 5% faster or more simply by
removing nothing but comments - the more comments I remove the faster
the code runs up to no more than 6% or 7%.

Ruby syntax seems to favor the notion that fewer characters is better
than more characters. Lexically interpreted langauges would want this
to be the case since it takes more effort to lex more characters.

Python runtimes are not affected by the number of characters one uses
such as extra whitespace or comments - removing comments does not make
Python code run faster simply because the comments have been removed.

Python has a very powerful JIT (Just In Time compiler) known as Psyco
with which certain Python expressions such as LC (List Comprehensions)
and others can be made to run 20x to 100x faster at runtime.

Recently as a test I wrote a rather simple Python program that
processed all characters of a 20 MB file by setting the MSB to 1. The
original Python code I began with executed in 65 seconds before I
began to optimize the code. After the code was fully optimized it ran
in just under 3 secs. After Psyco was used the runtime for the same
problem was less than 1 second.

The Ruby code I wrote before any optimizations were applied ran in
about 65 seconds or no faster than Python with no optimizations. The
most optimized Ruby code I could find for this problem was able to
execute in just under 22 seconds using techniques that were not
necessary when optimizing the Python code.

Given the best Ruby is capable of doing versus the best Python is
capable of doing Ruby ends up being more than 20x slower than Python
and I think I know why.

It is just not possible to make Ruby 1.8.6 execute any faster than the
Ruby interpreter is capable of executing the code due to the lack of a
byte-code driven VM. Maybe someday YARV will make Ruby code run 2x
faster than Ruby 1.8.6 but that day has not arrived yet and may never
arrived.

Even if YARV proves to be 2x faster than Ruby 1.8.6 the resulting Ruby
code will still be 10x slower than the fastest Python code.

The only way YARV will get faster than Python is whenever someone
codes a JIT compiler for YARV that provides the same performance boost
to Ruby that Psyco provides to Python. As far as I can tell nobody is
working on any such JIT for YARV and since YARV has been under
development for at least the last 14 to 18 months one can only surmise
a JIT for YARV would take a significant amount of time to produce and
release to the Ruby community.

The bottom line is that Python can be made to run as fast as machine
code but Ruby cannot.

I know some people want to try to use Ruby for every single problem
they are faced with but doing so would be less than wise since there
are no tools that work for all problems.

Some problems lend themselves nicely to Ruby such as Open Source
products where giving away the source code is not a business
problem.

Python is useful for problems that require fast runtimes such as 3D
modelling or video game programming.

Ruby would not be fast enough for the kinds of problems where people
are using Python.

I have not been able to find any references to Ruby being used for 3D
realtime video game programming but I have been able to find many
references to Python being used for 3D realtime video game
programming.

I don't expect those who read this to applaud my efforts to discuss
this in this forum however I feel we need to discuss this so that some
may choose to take actions to make Ruby run faster at runtime just as
work was done to make Python run faster at runtime.

Believe it or not I actually like Ruby 1.8.6 but I would hesitate to
try to use Ruby for situations where runtime performance was an issue
or whenever I did not want to release the source code.

When I write code I want to know I am using tools that give me the
best performance for the effort that I can possibly get as opposed to
tools that guarantee no matter how hard I work performance will always
be lacking.

The same comments could be made about Rails. Rails emits SQL
statements that have a lot of "*" characters. Those of us who have
been coding SQL long enough know the use of "*" characters makes SQL
statements run slower than when fully qualified column names are used
rather than the "*". I coded a simple benchmark that demonstrated
this very clearly; whenever "*" was used rather than a list of column
names the resulting SQL statements ran 10% to 880% slower than when
the "*" was replaced with a list of column names even when the list of
column names was quite long.

Oddly enough I quite easily found more powerful Database Frameworks
for Python that did not emit SQL code that used "*" characters and I
was even able to find some interfaces for those SQL Frameworks that
would allow seasonsed Rails developers use Rails statements when
describing their database relationships.

I know of some Ruby developers who rejected the idea that the use of
"*" in SQL statements would be slower than long lists of column
names. From the perspective of a Ruby on Rails developer who has not
coded anything but Rails or Ruby it might seem logical that fewer
characters is better than more characters and so the use of "*" in SQL
statements must be optimial because this is how Ruby works, right ?!?
Wrong !

Even when some RoR developers are faced with benchmarks that
demonstrate the use of "*" in SQL statements can be 10% to 880% slower
than not using "*" characters they still chose to reject the
benchmarks and deny the benefits of not using Rails because Rails is
not able to automatically replace "*" with lists of column names,
apparently.

When people choose to make their choices of languages a religious
issue they can become rather short-sighted in how they choose to
resolve programming problems.

I prefer to be agnostic about programming languages. I choose those
that perform the best and I ignore the rest.

Ruby is a cute language that may someday become useful but this won't
happen unless the Ruby community becomes interested in making Ruby
perform better at runtime. In the meantime, I will use Ruby only when
I must as for the rest I will most-likely use Python unless the
problem suggests another language may be more useful.

 
Reply With Quote
 
 
 
 
M. Edward (Ed) Borasky
Guest
Posts: n/a
 
      09-24-2007
Ruby Maniac wrote:
> Even if YARV proves to be 2x faster than Ruby 1.8.6 the resulting Ruby
> code will still be 10x slower than the fastest Python code.


Care to bet on that? I just benchmarked "YARV" at something like 5X Ruby
1.8.6, with some bursts as high as 72X!

 
Reply With Quote
 
 
 
 
Wilson Bilkovich
Guest
Posts: n/a
 
      09-24-2007
On 9/23/07, Ruby Maniac <(E-Mail Removed)> wrote:
> I welcome any corrections anyone might be able to make since I am new
> to Ruby with less than 3 months experience under my belt.
>

I'm not going to address any of your Rails comments, because they have
nothing to do with Ruby. Rails is just a library.

Python is not faster than Ruby due to language design, but because
skilled people got together and made it faster. Nothing is stopping
people from doing the same for Ruby.

Some corrections:
1. YARV is 'out', in the form of Ruby 1.9. A stable release is coming
in a matter of months.

2. JIT is nice, but it is not a panacea. C and C++ are plenty fast,
and use AOT compilation, not JIT. Java has shown that a combination of
AOT and JIT can yield impressive performance, but Psyco is merely one
approach out of many.

3. YARV has some (unfinished) competition with significantly varying approaches:
* JRuby: The trunk version offers compilation as well as
interpretation. At some point it will almost certainly support fancy
JIT tricks, given its architecture. http://jruby.codehaus.org/
* Rubinius: Currently supports 'only' AOT compilation to bytecode.
When it is done, we will be doing much more sophisticated things, a la
Pepsi/Coke/J3. http://rubini.us/
* IronRuby: I don't know enough about their architecture to say, but
they will probably bring some impressive performance to the table as
well.

Please don't judge Ruby the language by looking at the current 1.8
implementation. They are not the same thing, and the limitations of
1.8 are not necessarily invariant constraints.

On the other hand, I'm probably wasting my time with this reply.
Calling Ruby a "cute" language means you are almost certainly a troll.
Please forgive me if I am wrong about this.

 
Reply With Quote
 
Bill Kelly
Guest
Posts: n/a
 
      09-24-2007

From: "Ruby Maniac" <(E-Mail Removed)>
>
> I prefer to be agnostic about programming languages. I choose those
> that perform the best and I ignore the rest.


That's agnosticism? Sounds like a sermon from the Church
of Premature Optimization. <grin>

Kidding aside, that's great that you know what you want from
a programming language.

Many of us know what we want, too.

I accept that Ruby is slow to execute (although getting faster).
It's more important to me that Ruby is fun and productive to
program in, and that Ruby is merely _fast enough_ for the task
at hand.

I've dabbled in a number of languages, but I've written actual
production code in assembler, Forth, C, C++, Objective-C, Java,
Perl, Python, Ruby, and (kill me now) VB6.

If one took your "choose those that perform the best and ignore
the rest" razor literally, one would assume you would choose to
write only hand-tuned assembly.

Have you written much hand-tuned assembler lately? No? Neither
have I.

Fifteen to twenty years ago, it was still common for many video
games to be coded entirely in assembler. Myself, I preferred
to write as much as possible in C, and drop down to assembler
only when necessary.

Today, it's really the same equation. I write as much in Ruby
as possible, but drop down to C when needed.

Obviously, the faster Ruby gets, the better. But again, many
of us have been programming in Ruby for years, not because we
don't know half a dozen faster languages, but because we like
programming in Ruby, and find it fast enough for most of our
needs. And if some method needs to go way faster, there's
always C.


Regards,

Bill



 
Reply With Quote
 
Phrogz
Guest
Posts: n/a
 
      09-24-2007
On Sep 23, 8:50 pm, Ruby Maniac <(E-Mail Removed)> wrote:
> Ruby is a cute language that may someday become useful but this won't
> happen unless the Ruby community becomes interested in making Ruby
> perform better at runtime.


To be clear, it may someday become useful *to you*; it's already
useful to me.

> In the meantime, I will use Ruby only when
> I must as for the rest I will most-likely use Python unless the
> problem suggests another language may be more useful.


I'd be interested to know under what circumstance(s) you expect to be,
or already are, forced to use Ruby. (Developing RoR sites in a team
environment?)

 
Reply With Quote
 
John Joyce
Guest
Posts: n/a
 
      09-24-2007
Why do people troll?
What pleasure could it bring?

 
Reply With Quote
 
Michael T. Richter
Guest
Posts: n/a
 
      09-24-2007
--=-DebiaOMQneJ/gXKDwVpv
Content-Type: multipart/alternative; boundary="=-lcrn6u/mZnKmchr/4d/p"


--=-lcrn6u/mZnKmchr/4d/p
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Can I ask why *ANYBODY* took a message by someone calling themselves
"Ruby Maniac" and using expressions like "cute language" as anything but
a troll? Anybody? Anybody? Bueller?

Don't dignify these kinds of things with responses, peeps.

--=20
Michael T. Richter <(E-Mail Removed)> (GoogleTalk:
http://www.velocityreviews.com/forums/(E-Mail Removed))
Never, ever, ever let systems-level engineers do human interaction
design unless they have displayed a proven secondary talent in that
area. Their opinion of what represents good human-computer interaction
tends to be a bit off-track. (Bruce Tognazzini)

--=-lcrn6u/mZnKmchr/4d/p
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; CHARSET=3DUTF-8">
<META NAME=3D"GENERATOR" CONTENT=3D"GtkHTML/3.12.1">
</HEAD>
<BODY>
Can I ask why *ANYBODY* took a message by someone calling themselves &quot;=
Ruby Maniac&quot; and using expressions like &quot;cute language&quot; as a=
nything but a troll?&nbsp; Anybody?&nbsp; Anybody?&nbsp; Bueller?<BR>
<BR>
Don't dignify these kinds of things with responses, peeps.<BR>
<BR>
<TABLE CELLSPACING=3D"0" CELLPADDING=3D"0" WIDTH=3D"100%">
<TR>
<TD>
-- <BR>
<B>Michael T. Richter</B> &lt;<A HREF=3D"(E-Mail Removed)">ttmri=
(E-Mail Removed)</A>&gt; (<B>GoogleTalk:</B> (E-Mail Removed))<BR>
<I>Never, ever, ever let systems-level engineers do human interaction desig=
n unless they have displayed a proven secondary talent in that area. Their =
opinion of what represents good human-computer interaction tends to be a bi=
t off-track. (Bruce Tognazzini)</I>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

--=-lcrn6u/mZnKmchr/4d/p--

--=-DebiaOMQneJ/gXKDwVpv
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQBG90czLqyWkKVQ54QRApJvAJ46LU5Wzbr17cqjA07Aqx uldYqeFwCgsXQ0
tOYLjDBEzq4Mk4BWWTNS+Dw=
=hwAD
-----END PGP SIGNATURE-----

--=-DebiaOMQneJ/gXKDwVpv--

 
Reply With Quote
 
Mohit Sindhwani
Guest
Posts: n/a
 
      09-24-2007
John Joyce wrote:
> Why do people troll?
> What pleasure could it bring?
>


Fear, uncertainty and doubt - that's what drives people!

Cheers,
Mohit.
9/24/2007 | 1:25 PM.



 
Reply With Quote
 
M. Edward (Ed) Borasky
Guest
Posts: n/a
 
      09-24-2007
Michael T. Richter wrote:
> Can I ask why *ANYBODY* took a message by someone calling themselves
> "Ruby Maniac" and using expressions like "cute language" as anything but
> a troll? Anybody? Anybody? Bueller?
>
> Don't dignify these kinds of things with responses, peeps.
>


Well ... yes ... I suppose if I hadn't just run the benchmarks and
posted the results, I wouldn't have responded. But I am so thrilled to
see that 5X number for "YARV". Is there anyone here who thinks they can
get a 5X boost for Python 2.5? Perl 5.8.8? PHP 5?

 
Reply With Quote
 
Michael T. Richter
Guest
Posts: n/a
 
      09-24-2007
--=-+b2s378W/uy25t4HvOh+
Content-Type: multipart/alternative; boundary="=-N3spvnf/hcOZCE+B+suV"


--=-N3spvnf/hcOZCE+B+suV
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Mon, 2007-24-09 at 14:05 +0900, John Joyce wrote:

> Why do people troll?
> What pleasure could it bring?




Control. People whose daily lives have little in the way of things they
have control over like the illusion that upsetting other people and
having them react is like controlling their own lives.

--=20
Michael T. Richter <(E-Mail Removed)> (GoogleTalk:
(E-Mail Removed))
We should sell bloat credits, the way the government sells pollution
credits. Everybody's assigned a certain amount of bloat, and if they go
over, they have to purchase bloat credits from some other group that's
been more careful. (Bent Hagemark)

--=-N3spvnf/hcOZCE+B+suV
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; CHARSET=3DUTF-8">
<META NAME=3D"GENERATOR" CONTENT=3D"GtkHTML/3.12.1">
</HEAD>
<BODY>
On Mon, 2007-24-09 at 14:05 +0900, John Joyce wrote:
<BLOCKQUOTE TYPE=3DCITE>
<PRE>
<FONT COLOR=3D"#000000">Why do people troll?</FONT>
<FONT COLOR=3D"#000000">What pleasure could it bring?</FONT>
</PRE>
</BLOCKQUOTE>
<PRE>

</PRE>
Control.&nbsp; People whose daily lives have little in the way of things th=
ey have control over like the illusion that upsetting other people and havi=
ng them react is like controlling their own lives.<BR>
<BR>
<TABLE CELLSPACING=3D"0" CELLPADDING=3D"0" WIDTH=3D"100%">
<TR>
<TD>
-- <BR>
<B>Michael T. Richter</B> &lt;<A HREF=3D"(E-Mail Removed)">ttmri=
(E-Mail Removed)</A>&gt; (<B>GoogleTalk:</B> (E-Mail Removed))<BR>
<I>We should sell bloat credits, the way the government sells pollution cre=
dits. Everybody's assigned a certain amount of bloat, and if they go over, =
they have to purchase bloat credits from some other group that's been more =
careful. (Bent Hagemark)</I>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

--=-N3spvnf/hcOZCE+B+suV--

--=-+b2s378W/uy25t4HvOh+
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQBG906wLqyWkKVQ54QRAnknAKCacRmLkJJDcxi4Ewgey6 WOsxDv7ACgwvyK
+G3D9orfJYSZU5W5P3tnfD4=
=Tllk
-----END PGP SIGNATURE-----

--=-+b2s378W/uy25t4HvOh+--

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
XML Schema never-never occurence of declared elements / attributes Soren Kuula XML 1 12-01-2005 01:27 PM
can run javascript can't run vbscript - WHY duncan ASP .Net 2 10-27-2004 09:31 AM
string routines go to never never land on unix Kevin C Programming 4 10-17-2003 06:07 PM
Python is darn fast (was: How fast is Python) Michele Simionato Python 13 08-27-2003 03:58 AM



Advertisments