Which programming language is the fastest?
June 15, 2007
I recently came across The Computer Language Benchmarks Game that compares the speed of different programming languages on the Gentoo and Debian linux distributions. It’s interesting (although not super serious), but what does it say?
Firstly C and C++ are the winners on both the platforms. Then you have a whole bunch of languages listed, of which I’m mostly interested in Java, C# and Ruby. The latter two are about half as fast as C/C++ and Ruby is in the bottom of the list. Not so strange since Ruby is an interpreted scripting language. It would be interesting to know if the JIT-languages are tested when compiling for the first time, or when the code is cached in the memory for subsequent calls, since there can be a huge difference. Also, the C# code is run with Mono in the tests, and I don’t know if that has any performance implications as compared to the Microsoft .NET platform.
But my primary argument against this speed comparison is optimality. I’m sure that this argument has been made a thousand times by others, but still. The tests must have been performed on optimal code in all the languages, or else the comparisons wouldn’t have any validity at all. Then the question really is: how difficult is it to write optimal code in any of the programming languages in the test. There is a reason why there’s been an increase in high level languages and the usage of them, it’s because C/C++ makes it very easy to write bad code. How often do you have problems with memory leaks in C#? That’s right.
What I mean is that you probably don’t have to be a super programmer to write decent performing code in the higher level languages, you’d have more of a challenge doing it in C or Assembler. And apparently most developers weren’t good enough since there’s been such a shift in focus towards C#/Java. Think about Ruby on Rails for example, the active record wrapper makes it easy to quickly write some code that interacts with a database without getting horrible performance, whereas if you write the stored procedures/SQL yourself, stuff can get really messy if you’re not very good. Abstraction has good and bad sides.
I’m not being a sore loser here, I’m know that you can write really good performance code with C/C++. Just don’t accept the benchmarking tests you see without considering the circumstances.