On 11/3/05, Robert Bazinet <rbazinet / gmail.com> wrote:
> I am new to this list and Ruby in general. I had read a blog post recently
> that concerned me a bit,
> http://www.pankaj-k.net/archives/2005/11/ruby_or_java_a.html.
>
> The post points out two apps written to do the same task the same way, one
> in Java and the other in Ruby. The Java application turned out to be 12x
> faster than the Ruby app. I know we are not really comparing apples to
> apples here but I was wondering if there are any real-world test results out
> there that show Ruby's performance vs. other languages and where Ruby stacks
> up.

This topic comes up every few months on this list, and you might find
it interesting to search the archives at either ruby-talk.org or
comp.lang.ruby on Google Groups.

But to sum things up:

Yes Java is quite a bit faster than Ruby. In fact other scripting
languages like Perl and Python are also faster. Most of this is due to
the fact that Ruby does not in fact have a VM, as Mr. Kumar suggests.
It actually evaluates an AST (Abstract Syntax Tree, the result of
parsing) directly. There is currently work being done to create a VM
for Ruby, called YARV (http://www.atdot.net/yarv/.) This will make
Ruby much faster.

Still even when Ruby gets a VM Java will probably always be faster,
for a few reasons:
1. Java is a statically typed language, which allows for many more
optimizations that are harder or impossible in a dynamically typed
language like Ruby.
2. Java has many man-years and millions of dollars invested in making
it fast. Ruby does not have a huge corporation with thousands of
programmers behind it. Despite that Ruby does pretty darn good, and in
fact Ruby is probably faster than Java was back in the early days.

Also, I would suspect that Mr. Kumar's Ruby code could benefit from
some tweaking by the experts on this list. Recent threads have shown
that smarter algorithms can make Ruby code much, much faster. In my
opinion his run against his log files seems absurdly slow.

Also when it comes to web development, runtime performance of the
language itself has less of an impact, as network latency and in
particular, database access, are usually the bottlenecks.

Regards,
Ryan