Hasty benchmarking of various programming languages

Michael wants his CPU cycles back! Anyhow, using some benchmarking, we can make comparisons between languages (or rather, some implementations). Here are some possible conclusions (using an AMD CPU which is what I own):

  • Python is faster than Perl.
  • Python is faster than Ruby by a wide margin.
  • Python is much faster than PHP .
  • C++ is faster than Lisp and uses much less memory and Lisp is much faster than Python but Lisp uses more memory.
  • C++ is generally slightly faster than Java, but not always though Java uses a lot more memory.
  • PHP and Ruby are pretty much on par but Ruby uses less memory.
  • JavaScript is slightly faster than PHP but Perl is faster than JavaScript.
  • Lisp and Java are on par.
  • Lisp is slightly faster than Haskell, but not always.
  • C++ is faster than Haskell, but not always.
  • Haskell and Java are pretty much on par, but Java uses much more memory.
  • the famous Intel C/C++ compiler is on par with GCC (Parand points out the benchmarking involves AMD processors!).
  • Ocaml is on par with C++.
  • Ocaml is much faster than Haskell.
  • Ocaml is better than Java.
  • Ocaml is better than Lisp.

The lessons here are:

  • Java is fast, as fast as C++ but its memory usage is worse than a language like Python.
  • Python is one of the fastest high level languages out there, but Perl is close behind.
  • PHP and Ruby are slow.
  • Languages like Lisp, Ocaml and Haskell can sometimes be used as replacement for C++ even when performance is a concern.
  • GCC is a good enough compiler.

Yes, I’m aware of the limitations of this analysis!!!

8 thoughts on “Hasty benchmarking of various programming languages”

  1. Daniel, cheers for putting this together! I was planning on doing this sometime soon, but you’ve taken all the work out of it.

  2. Merci, that’s easy enough to read. Of course, there is always the The Computer Language Shootout (nsieve example) if you’re looking for more numbers.

  3. If I’m reading this right the benchmark’s on the AMD Sempron, so the Intel compiler vs. GCC comparison may not apply. I doubt Intel has optimized their compiler for AMD.

  4. Another lesson is that the managed, JIT-compiled languages produce programs that take a long time to start up. I would say that this argues against using them for small, interactive applications in which startup time is more of an issue. Of course, if you can precompile the program ahead of time to native code…

  5. Also, whether a language A is truly faster than a language B depends on the developer. In Python, for instance, there are several constructs for creating loops, such as list comprehension, the map function, the for loops, and I suppose a recursive function is also an alternative.

    But which of these provide the best performance (in the given situation)? The answer might not always be intuitive to the developer and hence, in reality, the result of benchmarking depends a great deal on the developer’s ability to avoid common pitfalls of the language.

  6. Daniel, you seem not to have noticed the Intel Pentium 4 measurements – we’re continually re-working the website and benchmarks, so take another look, Java might look faster to you now.
    ;
    http://shootout.alioth.debian.org/

    Thanks. Java looked fast, and it still looks fast. My problem is memory usage.

    “the famous Intel C/C++ compiler is on par with GCC”

    The link seems to compare GNU C with Intel C++ wouldn’t it be more reasonable to compare GNU C with Intel C – or GNU C++ with Intel C++ ?

    Fixed. It doesn’t change the analysis.

    “PHP and Ruby are slow”

    Slow at what? šŸ™‚

    http://shootout.alioth.debian.org/gp4/benchmark.php?test=regexdna&lang=all

    These benchmarks show Python doing very well compared to Ruby and PHP.

    Do you recognise any of the authors of the Haskell programs?

    Now, do you recognise any of the authors of the Java programs?

    Hmmm….

    “Python is one of the fastest high level languages out there”

    Compare with Lua. Compare with Chicken Scheme. Compare with VisualWorks Smalltalk.

    Yes. There are all interesting all level languages faster than Python.

    Look at Psyco.

    Psyco looks more like an experiment at this point.

    -Daniel

  7. Daniel, you seem not to have noticed the Intel Pentium 4 measurements – we’re continually re-working the website and benchmarks, so take another look, Java might look faster to you now.
    http://shootout.alioth.debian.org/

    “the famous Intel C/C++ compiler is on par with GCC”
    The link seems to compare GNU C with Intel C++ wouldn’t it be more reasonable to compare GNU C with Intel C – or GNU C++ with Intel C++ ?

    “PHP and Ruby are slow”
    Slow at what? šŸ™‚
    http://shootout.alioth.debian.org/gp4/benchmark.php?test=regexdna&lang=all

    Do you recognise any of the authors of the Haskell programs?
    Now, do you recognise any of the authors of the Java programs?

    “Python is one of the fastest high level languages out there”
    Compare with Lua. Compare with Chicken Scheme. Compare with VisualWorks Smalltalk.
    Look at Psyco.

  8. i like the analysis with the exception of highly unintelligable relative terms used in certain cases to distinguish this heirarchy of importance between languages. keep it science. performance is the topic in comparison, not relativistic personal bias.

    thanks again for the analysis, i got something out of it. šŸ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax