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.


16 Responses to “Which programming language is the fastest?”

  1. Isaac Gouy Says:

    “Firstly C and C++ are the winners…”
    – Include memory use and “the winner” is … Free Pascal.

    “Ruby is in the bottom of the list. Not so strange since Ruby is an interpreted scripting language.”
    – As are some of the languages above it – Lua, Pike, Python …

    “if the JIT-languages are tested when compiling for the first time … since there can be a huge difference”
    – Inquiring minds read the FAQ
    – I guess it depends on your definition of “huge” and “tiny”

    “The tests must have been performed on optimal code in all the languages, or else the comparisons wouldn’t have any validity at all.”
    – The more interesting criticism is that the programs are /too/ optimized, that they have had more care and attention than would happen in ordinary programming.

    As you argue that it’s more difficult to write programs in C and easier in higher level languages – Java, Ruby – are the people who contributed C programmers superprogrammers and the people who contributed Ruby programs way below average?

  2. Luka Says:

    JavaScript written by Indian developers will be the fastest of all!

  3. robotz Says:

    If you are talking execution speed, OCaml, or objective CAML is the fastest programming language. Around 10% faster than C on average.

  4. anicake Says:


    yes. OCaml is the one that i came across as the fastest at the end of my search for the fastest. anyway. if someone reads this, but has something more to add, or knows any other language that is faster: please reply to this thread. i will be notified and i shall read your post. and add to my knowledge.
    thank you.

  5. Daniel Says:

    Assembly Language hands down

  6. anicake Says:

    of course you cant compare high level languages with assembly. and that every sane person knows. i think i want to know if there is any language that is faster than ocaml, and requires a ‘compiler’. because in assembly there is only one-to-one mapping to the instruction set of the processor. i think a discussion about compiled languages and their benchmark results is what many people would be interested to know about.


  7. prakash Says:

    @robotz – what are you talking about? According to Wikipedia the author of OCaml states this “OCaml delivers at least 50% of the performance of a decent C compile”. nothing beats a good “C” code (It is commonsense as “C” is very closely tied to Assembly)

  8. TheGreatAndyChow Says:

    I’m very interested in this topic. GNU projects tend to favor C. I’ve always found C to be very elegant, simple and logical. But I’d love to see a language such as ‘Ruby’ become efficient like C. I like automatic memory management, i.e. garbage collection. Also, I’d like to have the option of object oriented programming, without the very confusing C++ construct. And C code does get unclear rather easily.

    Still, up to now, it seems like C is the only ‘real’ programming language. It’s power, flexibility and elegance is undeniable. All other programming languages seem like toys, which break when you want to do something real, not just a Hello World. It appears to be the only ‘sane’ language.

    • Scara Says:

      If you like C and you want “a better C” get a look to the D programming language.
      OCaml and Haskell, anyway, are High-level language close to C in performances…

  9. vignesh Says:

    My opinion about C is “It is one of the fastest computer language”. Apart from this it has limited number of functions that are predefined. Most of other languages have too many predefined functions and class hierarchy, that’s too difficult to remember during programming.

  10. cyclone2engine Says:

    fast and efficient, that’s what “C” is about. And if “C” isnt fast enough for you. Then use inline assembly
    ‘within’ C.

  11. cyclone2engine Says:

    Fast and efficient, that’s what “C” is about. And if “C” isnt fast enough for you. Then use inline assembly ‘within’ C. Just let me know if you can outperform C’s optimization.

  12. Dan Eloff Says:

    You’re all thinking about optimizing for the computer’s time (which is cheap) instead of the programmer’s time (which is not). That’s the wrong optimization from a return on investment point of view in most cases. Furthermore with higher-level languages you can usually rewrite a troublesome hotpath or inner loop in C, compile it and call it from your high level language. In high-level languages with a JIT they are usually close enough to C speed that it’s not worth the effort (Remember there is never a business need for the “fastest” program, just a “fast enough” program.) In light of all that, C is very rarely the most “sane” language for the job!

    • DrShebl Says:

      I 100% agree with you. The programmers time and effort in writing an efficient yet error-free code is the most precious. In this aspect, can you share with me some fast languages and efficient for the programmer? I will be notified by email to share my experience with you. Thanks.

  13. lazy boy Says:

    Actually, the c and the c++ programming languages are by far the fastest compiled programming languages however if you really want speed than c with assembly packages to do the hard stuff is going to out perform ANY other high level language.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: