—
There are newer benchmarks: C++ vs. Python vs. PHP vs. Java vs. Others performance benchmark (2016 Q3)
—
The benchmarks here do not try to be complete, as they are showing the performance of the languages in one aspect, and mainly: loops, dynamic arrays with numbers, basic math operations.
This is a redo of the tests done in previous years. You are strongly encouraged to read the additional information about the tests in the article.
Here are the benchmark results:
Language | CPU time | Slower than | Language version |
Source code |
|||
---|---|---|---|---|---|---|---|
User | System | Total | C++ | previous | |||
C++ (optimized with -O2) | 0.952 | 0.172 | 1.124 | – | – | g++ 5.3.1 | link |
Java 8 (non-std lib) | 1.332 | 0.096 | 1.428 | 27% | 27% | 1.8.0_72 | link |
Python 2.7 + PyPy | 1.560 | 0.160 | 1.720 | 53% | 20% | PyPy 4.0.1 | link |
Javascript (nodejs) | 1.524 | 0.516 | 2.040 | 81% | 19% | 4.2.6 | link |
C++ (not optimized) | 2.988 | 0.168 | 3.156 | 181% | 55% | g++ 5.3.1 | link |
PHP 7.0 | 6.524 | 0.184 | 6.708 | 497% | 113% | 7.0.2 | link |
Java 8 | 14.616 | 0.908 | 15.524 | 1281% | 131% | 1.8.0_72 | link |
Python 3.5 | 18.656 | 0.348 | 19.004 | 1591% | 22% | 3.5.1 | link |
Python 2.7 | 20.776 | 0.336 | 21.112 | 1778% | 11% | 2.7.11 | link |
Perl | 25.044 | 0.236 | 25.280 | 2149% | 20% | 5.22.1 | link |
PHP 5.6 | 66.444 | 2.340 | 68.784 | 6020% | 172% | 5.6.17 | link |
The clear winner among the script languages is… PHP 7. 🙂
Yes, that’s not a mistake. Apparently the PHP team did a great job! The rumor that PHP 7 is really fast confirmed for this particular benchmark test. You can also review the PHP 7 infographic by the Zend Performance Team.
Brief analysis of the results:
- NodeJS got almost 2x faster.
- Java 8 seems almost 2x slower.
- Python has no significant change in the performance. Every new release is a little bit faster but overall Python is steadily 15x slower than C++.
- Perl has the same trend as Python and is steadily 22x slower than C++.
- PHP 5.x is the slowest with results between 47x to 60x behind C++.
- PHP 7 made the big surprise. It is about 10x faster than PHP 5.x, and about 3x faster than Python which is the next fastest script language.
The tests were run on a Debian Linux 64-bit machine.
You can download the source codes, an Excel results sheet, and the benchmark batch script at:
https://github.com/famzah/langs-performance
