Objections
These are the objections we expect, with our answers and the numbers behind them.
Isn't Python interpreted?
CPython compiles every file to bytecode, and a virtual machine runs the bytecode. Python's documentation calls that virtual machine the interpreter, which is where the confusion starts. A real interpreter executes the source text or the syntax tree directly and repeats the translation work as it goes. Shell scripts do. Python does not.
Isn't Java interpreted until the JIT starts?
With the JIT switched off, the JVM runs the bytecode and never makes machine code. In our test that was slower than Python: 3,235 ns against 1,531 ns on the class code. Nobody runs Java that way. The default setting compiles hot methods quickly, and the program ends up about 80 times faster.
Isn't JavaScript interpreted?
V8 compiles each function the first time the program calls it, and it compiles hot code to machine code. With machine code switched off the program runs about 14 times slower on our class code.
Doesn't C++ compile straight to machine code, so it is always fast?
It does compile to machine code. The speed depends on the optimizer setting. C++ at -O0 took 2,027 ns on our class code, slower than CPython at 1,531 ns. At -O1 it took 162 ns.
Are you saying all languages run equally fast?
Yes. A language is a specification on paper, and a specification has no speed. Speed belongs to an implementation, and an implementation runs as fast as the human hours spent on optimizing it and compiling it to machine code allow.
Our numbers show how large the effect of those hours is. CPython and PyPy both implement Python, and PyPy runs our program about five times faster. Java with its JIT off and Java with its full JIT are one implementation at two settings, and they differ by about 80 times. C++ built with -O2 is about 14 times faster than CPython on our class code. That gap compares two implementations. It does not compare two languages.
Isn't the benchmark unfair to my language?
We wrote one program in 11 languages and kept the versions as close as the languages allow. The code is average code, and no language got performance tuning. Any language can run faster if someone tunes the code for it. For each language we also picked the benchmarking tool and loop that made the class code look best, so any bias in the numbers favors the class code.
Why not use the Benchmarks Game?
The Benchmarks Game compares programs that contributors have tuned for speed. We measure ordinary code, because most code is ordinary.
You ran this on a virtual server.
Yes. It is a rented eight-core virtual machine, and it hides its real cache layout. Treat the figures as a demonstration of how big each effect is, not as exact numbers for your machine. The code is public, so you can run it on yours.