Categories: Development

PHP 7.1, 7.2, 7.3 and 7.4 benchmarks and comparisons

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.

 

php 7.1 benchmark
php 7.2 benchmark
php 7.3 benchmark
php 7.4 benchmark
Share
Tags: PHPWeb Dev

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

2 years ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

2 years ago

Early September spring shots

Some early September spring shots from a bushwalk, It is still too early for wildflowers.

3 years ago

Cloning an NVMe to SK Hynix Platinum P41 NVMe

I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…

3 years ago

Using Laravel’s deleteDirectory to delete folders and their contents

If you ever needed a simple solution in Laravel to delete an entire directory and…

3 years ago

How to allow only 1 user to register in a Laravel application

How to enforce only one user to register or be registered in a Laravel web…

3 years ago