Google has published a paper (PDF) comparing performance of four programming languages, C++, its own language Go, Java and Scala. A team at Google created a “simple and compact” benchmark that didn’t take advantage of language-specific features. An algorithm was implemented using each language’s “idiomatic container classes, looping constructs, and memory/object allocation schemes.”

However, the paper notes: “While the benchmark itself is simple and compact, it employs many language features, in particular, higher-level data structures (lists, maps, lists and arrays of sets and lists), a few algorithms (union/find, dfs/deep recursion, and loop recognition based on Tarjan), iterations over collection types, some object oriented features, and interesting memory allocation patterns.”

Above: Run-time measurements, including a few optimizations.

After benchmark tests were published within Google various employees took a stab at optimizing the code for specific languages.

The conclusions:

  • C++ provides the best performance by far, but it requires the most extensive language-specific tuning.
  • Scala provides the most concise notation and optimization of code complexity.
  • The algorithm was simplest to implement in Java, but garbage collection settings make both Java and Scala difficult to benchmark accurately.
  • Go offers concise notion and very fast compile time, but is still immature.

The phrase “lies, damn lies and benchmarks” is by now a cliche. Suffice it to say, benchmarks never tell the full story, and there are many factors to consider when choosing a programming language. That said, you may find parts of this paper enlightening, especially with regards to Scala performance.