By dnene
via blog.dhananjaynene.com
Published: Jul 08 2008 / 11:53
Performance comparison for a small piece of logic across a number of languages. Some of the interesting findings (I emphasise - in this context) are : Java faster than C++, Java about a 100 times faster than Python / Ruby, JRuby faster than Ruby 1.9, Ruby 1.9 twice as fast as Python, Python / Ruby faster than Groovy, and PHP and Jython bringing up the rear.
Comments
daniel replied ago:
Very interesting benchmark. One of the more interesting conclusions: Java is faster than C++...by a wide margin. Ruby, Groovy, Python and friends all get a showing as well. Worth the read.
Umberto Zappia replied ago:
Would be nice to explain why some voted this down.
alphadog replied ago:
Two reasons I voted down:
1. A "one-algorithm test" is hardly a way to compare language/compiler performance.
2. The end results don't jibe with my (semi-objective) reality that :
C++ > Java > (Python 2.5.1 ~ Groovy 1.6 ~ Ruby 1.9)
Meaning C++ is generally faster than Java, which is generally faster than the set of popular, dynamic languages.
Check out http://shootout.alioth.debian.org/gp4/index.php for a broader set of performance metrics than one piece of specific code.
Dhananjay Nene replied ago:
alphadog,
I am just a little surprised - both your views are actually quite explicitly stated in the blog post (they are not even tucked into the fine print).
I believe there is indeed a case for one-algorithm tests to be blogged about.. something I am starting to suspect (though have no way to offer any additional supporting evidence or to reach a definitive conclusion)
a. In this case Java is faster than C++ because its garbage collector is outperforming the manual memory allocation in C++. Given that the code itself runs very fast in the two languages, the gc is suddenly important.
b. In this case Python is a little slower than ruby because its attribute access could be slower
Given the fact that I couldn't attach a high supporting evidence to these hypothesis, I chose to not very explicitly state it. But a post like this can still help people understand a little bit more within a specific context.
It is quite helpful when someone explains their votes. Thank you for your vote and comment.
Dhananjay
alphadog replied ago:
You may be surprised, because often what one intends and what another perceives out of a blog post are not exactly the same.
I realize you may have intended to ensure that the above two observations of mine are in your blog, but the result is different. Those two important observations are in a "note" as an "aside".
You then go on, armed with bullet-points and bold letters which strikes the reader as "important" :), to say some over-generalizations that can easily be misconstrued, especially since they are based on a very focused, and probably unoptimized, set of code.
I totally realize I'm being picky, but that's why I voted down.
Dhananjay Nene replied ago:
Understand you much more clearly now. I'll take that as a useful learning.
zynasis replied ago:
nice work
pt93903 replied ago:
Really appreciate the effort put into this.
Voters For This Link (31)
Voters Against This Link (8)