• Home
  • -
  • PHP Performance over time: PHP 5.6 - PHP 8.0 RC3

PHP Performance over time: PHP 5.6 - PHP 8.0 RC3

About six years ago, I was at a point where I nearly gave up on PHP. For fun, I solved Project Euler puzzles, and PHP (at that time, I was using a 32-bit version on top of it) was excruciatingly slow when solving these puzzles. Fast-forward to 2020: I had the puzzles I solved back then lying around on Github. As those consist mainly of math, nothing changed functionality wise - but they are a perfect starting point to see how PHP Performance changed over time.

Setup

In 2014, I already implemented a microtime-based timer to get performance measurements. PHPUnit test cases trigger the execution of the code. For each test round, I did a composer update to get a setup matching the used PHP version. The PHP versions are all installed directly on WSL2 Ubuntu 20 via the Ondrej PPA.

The test code

You can take a look at the test code (or try it yourself) at https://github.com/susannemoog/proj-euler - but please keep in mind the bulk of that code is 6 years old :-D

Results - Table View


Results show only the results with the greatest difference for brevity - the total time however is the complete run time of all tests.

TEST (Time in ms) PHP 5.6 PHP 7.0 PHP 7.1 PHP 7.2 PHP 7.3 PHP 7.4 PHP 8.0RC3
Total Run Time 28.76s 14.92s 13.47s 13.43s 12.62s 10.78s 8.77s
DivisableTriangleNumber 2555 1313 1299 1234 1130 1068 834
LongestCollatzSequence 1255 529 458 458 472 380 179
AmicableNumbers 89 52 43 42 39 42 27
NameScores 26 26 25 25 19 22 21
NonAbundantNumbers 2356 867 806 817 744 686 412
QuadraticPrimes 358 177 174 177 156 109 73
CircularPrimes 674 221 202 214 163 165 137
DoubleBasePalindromes 385 166 165 143 141 124 104
TruncatablePrimes 686 224 209 200 166 211 138
LargestPalindromeProduct 357 130 100 93 106 105 73
PandigitalPrime 522 162 140 135 109 98 106
PentagonNumbers 292 87 79 80 76 49 47
FourDistinctPrimeFactors 10537 5728 4821 4982 4747 3600 3077
SmallestMultiple 3185 1727 1606 1574 1490 1402 1090
PrimeDigitReplacements 177 105 94 96 87 75 61
PermutedMultiples 281 130 116 121 115 103 88
CombinatoricSelections 1226 1187 1094 1091 1077 1051 1067

Results - Graph

php - all php - total time

Conclusion

As you can see, the performance improvements happening over time are impressive and continuous; so today, I would probably have no problems solving the puzzles. Of course, it always depends a bit on your use case, but chances are good you'll profit at least a bit from every upgrade. If you are still stuck on an older PHP version and needed (another) argument to upgrade - here you go. ;)

Links