Putting PHP versions 7.1, 7.2, 7.3 and 7.4 against each other in a simple benchmark driven comparison for time taken to do calculations.
Results are from using this benchmark script. Value is in seconds, lower is better.
Version | 7.1 | 7.2 | 7.3 | 7.4 |
Math | 0.116 | 0.106 | 0.107 | 0.117 |
String | 0.181 | 0.161 | 0.148 | 0.145 |
Loops | 0.009 | 0.008 | 0.008 | 0.006 |
If else | 0.016 | 0.009 | 0.010 | 0.006 |
Calculation total | 0.321 | 0.285 | 0.272 | 0.273 |
MySQL total | 0.230 | 0.224 | 0.233 | 0.227 |
TOTAL | 0.551 | 0.509 | 0.506 | 0.500 |
Test were ran on a Vultr $6 p/m high-frequency instance (1CPu, 1GB mem) with Ubuntu 18.04 x64
The total times were as expected, the older version gets pipped by its successor. PHP 7.4 really is the fastest version although that was completely expected beforehand.
PHP 7.1 is from 2016 and since December 1st 2019 is no longer supported. This version is 3 years older than 7.4 and honestly doesn’t show a noticeable drop-off in its performance.
What is interesting is that PHP 7.4 match calculation was the slowest amongst the versions. The math calculation code is this:
function test_math(&$result, $count = 99999) { $timeStart = microtime(true); $mathFunctions = array("abs", "acos", "asin", "atan", "bindec", "floor", "exp", "sin", "tan", "pi", "is_finite", "is_nan", "sqrt"); for ($i = 0; $i < $count; $i++) { foreach ($mathFunctions as $function) { call_user_func_array($function, array($i)); } } $result['benchmark']['math'] = timer_diff($timeStart) . ' sec.'; }
PHP 7.4 just could not do the equations better than its predecessors. Again this would not be noticeable without a number reading.
Ground was made up with PHP 7.4 in the if else test.
function test_ifelse(&$result, $count = 999999) { $timeStart = microtime(true); for ($i = 0; $i < $count; $i++) { if ($i == -1) { } elseif ($i == -2) { } else { if ($i == -3) { } } } $result['benchmark']['ifelse'] = timer_diff($timeStart) . ' sec.'; }
It got a standout result compared to the other versions. Faster speed with conditional statements would likely be preferred to math calculations in todays PHP usage.
These performance results whilst stating which version is fastest doesn’t change the general consensus that staying up to date with versions is the right thing because of security and support.
PHP 7.4 is the fastest, it’s also the latest and in focus version for stability. If you’re not game for 7.4 at least be on version 7.2 or 7.3 and no less. PHP version 7.2 loses its support late 2020.