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
···
On 11/3/05, Robert Bazinet <rbazinet@gmail.com> wrote:
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.
In most cases, the same algorithm implemented in Java and in Ruby is
going to be faster/more memory-efficient in Java, at least with the
current Ruby implementation (there is no "Ruby VM" as the author
supposes; the current interpreter just walks an AST).
However, Ruby can often make more efficient algorithms easier to write
and use (hence the performance benefits that have been observed with
Rails).
If speed is your most important criterion, for which all others must be
sacrificed, Ruby is (probably) not the right language; but usually there
are other factors, like programmer time -- especially for personal
projects!. In those cases, the analysis that needs to be made is
whether a language is fast enough for your specific task.
If anyone offers you a universally applicable "performance metric", it
is an illusion.
-mental
···
On Fri, 2005-11-04 at 05:45 +0900, Robert Bazinet wrote:
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.
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.
I could not say what the comparable gains in Java would be but that ruby
code could use some algorithmic optimization.
OTOH, if speed really was the issue, one should go with ASM or something. My
grasp on the ruby philosophy isn't just to write the most efficient code,
but to have fun while writing it.
/Johan
···
On 11/3/05, MenTaLguY <mental@rydia.net> wrote:
On Fri, 2005-11-04 at 05:45 +0900, Robert Bazinet 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.
In most cases, the same algorithm implemented in Java and in Ruby is
going to be faster/more memory-efficient in Java, at least with the
current Ruby implementation (there is no "Ruby VM" as the author
supposes; the current interpreter just walks an AST).
However, Ruby can often make more efficient algorithms easier to write
and use (hence the performance benefits that have been observed with
Rails).
If speed is your most important criterion, for which all others must be
sacrificed, Ruby is (probably) not the right language; but usually there
are other factors, like programmer time -- especially for personal
projects!. In those cases, the analysis that needs to be made is
whether a language is fast enough for your specific task.
If anyone offers you a universally applicable "performance metric", it
is an illusion.
I've done some benchmarking and the biggest CPU hog is the call to
DateTime.strptime. By changing that call to just DateTime.new
(arguably removing some functionality from the class), the runtime
performance of 10,000 iterations of calling LogEntry.new goes from
24.18 seconds to 7.39 seconds, on my laptop (P4 2.8 GHz, 1 GB RAM,
Windows XP, similar to his test system.)
I believe his regular expressions could be improved as well. Anyone up
to the challenge of making this LogEntry class much faster?
Ryan
···
On 11/3/05, Ryan Leavengood <leavengood@gmail.com> wrote:
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.
If speed is your most important criterion, for which all others must
be sacrificed, Ruby is (probably) not the right language;
Yes, in this case C is probably the good language because it allows you
to write Ruby C extensions.
If anyone offers you a universally applicable "performance metric", it
is an illusion.
Yes, this illusion only point out the fact that 'performance' is, by
itself, an illusion when it is not related to some goal or issue which
may be illusive too.
> 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.
In most cases, the same algorithm implemented in Java and in Ruby is
going to be faster/more memory-efficient in Java, at least with the
current Ruby implementation (there is no "Ruby VM" as the author
supposes; the current interpreter just walks an AST).
On Fri, 2005-11-04 at 05:45 +0900, Robert Bazinet wrote:
However, Ruby can often make more efficient algorithms easier to write
and use (hence the performance benefits that have been observed with
Rails).
If speed is your most important criterion, for which all others must be
sacrificed, Ruby is (probably) not the right language; but usually there
are other factors, like programmer time -- especially for personal
projects!. In those cases, the analysis that needs to be made is
whether a language is fast enough for your specific task.
If anyone offers you a universally applicable "performance metric", it
is an illusion.
Thank you and the others that replied to my post. As I said, I am new to
Ruby and am learning it. I have a couple projects I would like to do in Ruby
but with his blog post it got me to wondering if there was a huge difference
in performance.
I would imagine there is always proven ways to do something in any language.
I did see the YARV project in poking around the web for Ruby information,
but this looks like it won't be implemented for a while in the mainstream
Ruby release.
-Rob
···
On 11/3/05, Ryan Leavengood <leavengood@gmail.com> wrote:
On 11/3/05, Ryan Leavengood <leavengood@gmail.com> wrote:
>
> 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.
I've done some benchmarking and the biggest CPU hog is the call to
DateTime.strptime. By changing that call to just DateTime.new
(arguably removing some functionality from the class), the runtime
performance of 10,000 iterations of calling LogEntry.new goes from
24.18 seconds to 7.39 seconds, on my laptop (P4 2.8 GHz, 1 GB RAM,
Windows XP, similar to his test system.)
I believe his regular expressions could be improved as well. Anyone up
to the challenge of making this LogEntry class much faster?
I would like to see this LogEntry class be rewritten and sent to the author
to Mr. Kumar and rerun the tests to see what optimized code in Ruby can do
against his Java code.
I plan to do my next couple projects in Ruby and use these as a learning
tool for Ruby. I think with the addition of a VM it should make some nice
strides.
Thanks for all that responded.
-Rob Bazinet
···
On 11/3/05, Ryan Leavengood <leavengood@gmail.com> wrote:
On 11/3/05, Ryan Leavengood <leavengood@gmail.com> wrote:
>
> 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.
I've done some benchmarking and the biggest CPU hog is the call to
DateTime.strptime. By changing that call to just DateTime.new
(arguably removing some functionality from the class), the runtime
performance of 10,000 iterations of calling LogEntry.new goes from
24.18 seconds to 7.39 seconds, on my laptop (P4 2.8 GHz, 1 GB RAM,
Windows XP, similar to his test system.)
I believe his regular expressions could be improved as well. Anyone up
to the challenge of making this LogEntry class much faster?
Thank you and the others that replied to my post. As I said, I am new to
Ruby and am learning it. I have a couple projects I would like to do in Ruby
but with his blog post it got me to wondering if there was a huge difference
in performance.
I would imagine there is always proven ways to do something in any language.
I did see the YARV project in poking around the web for Ruby information,
but this looks like it won't be implemented for a while in the mainstream
Ruby release.
Another option that you could pursue is writing your code in Ruby,
profiling it, and
rewriting bottlenecks in C with RubyInline (if you can't get enough of
a performance
boost out of algorithmic changes).
zenspider has shown some very good results through following the
profile-benchmark-optimize-rewrite in C model.
···
On 11/3/05, Robert Bazinet <rbazinet@gmail.com> wrote:
I would like to see this LogEntry class be rewritten and sent to the author
to Mr. Kumar and rerun the tests to see what optimized code in Ruby can do
against his Java code.