The PHP team has released PHP 8.2.0 on 8 Dec 2022. This version contains many new features like readonly classes, Disjunctive Normal Form (DNF) types, new "Random" extension, constants in traits, etc.
I was curios to benchmark the execution time of this release compared with the previous ones until PHP 7.4.33, that recently became unsupported on 28 Nov 2022.
I used the Zend/bench.php script to run the experiment, getting the total execution times. This script is included with the PHP source code and it was created for testing the language using some math operators, nested loops, array, strings and recursive functions.
I used the latest PHP versions available, as follows:
I executed the experiment using an 11th Gen Intel(R) Core(TM) i9-11950H CPU @ 2.60GHz, with 32GB RAM, HD SSD running Linux Ubuntu 22.04.1 LTS.
For the PHP 8 versions, I also executed the Zend/bench.php script using the Just In Time compiler (JIT). I used the following command:
php -dopcache.enable_cli=1 -dopcache.jit_buffer_size=256M path/to/Zend/bench.php
If you are not familiar with the JIT feature of PHP 8, I suggest to read this excellent article.
Results
Here the results (in seconds) for each PHP versions:
PHP 8.2.0
simple 0.005 simplecall 0.002 simpleucall 0.006 simpleudcall 0.008 mandel 0.036 mandel2 0.038 ackermann(7) 0.009 ary(50000) 0.002 ary2(50000) 0.002 ary3(2000) 0.018 fibo(30) 0.031 hash1(50000) 0.003 hash2(500) 0.004 heapsort(20000) 0.011 matrix(20) 0.011 nestedloop(12) 0.009 sieve(30) 0.006 strcat(200000) 0.002 ------------------------ Total 0.200
PHP 8.2.0 + JIT
simple 0.001 simplecall 0.000 simpleucall 0.000 simpleudcall 0.000 mandel 0.005 mandel2 0.006 ackermann(7) 0.004 ary(50000) 0.002 ary2(50000) 0.001 ary3(2000) 0.004 fibo(30) 0.009 hash1(50000) 0.002 hash2(500) 0.002 heapsort(20000) 0.004 matrix(20) 0.002 nestedloop(12) 0.002 sieve(30) 0.002 strcat(200000) 0.001 ------------------------ Total 0.047
PHP 8.1.13
simple 0.005 simplecall 0.002 simpleucall 0.006 simpleudcall 0.008 mandel 0.036 mandel2 0.038 ackermann(7) 0.009 ary(50000) 0.003 ary2(50000) 0.002 ary3(2000) 0.020 fibo(30) 0.030 hash1(50000) 0.003 hash2(500) 0.003 heapsort(20000) 0.010 matrix(20) 0.011 nestedloop(12) 0.010 sieve(30) 0.006 strcat(200000) 0.002 ------------------------ Total 0.203
PHP 8.1.13 + JIT
simple 0.001 simplecall 0.000 simpleucall 0.000 simpleudcall 0.000 mandel 0.005 mandel2 0.006 ackermann(7) 0.004 ary(50000) 0.002 ary2(50000) 0.001 ary3(2000) 0.005 fibo(30) 0.009 hash1(50000) 0.002 hash2(500) 0.002 heapsort(20000) 0.004 matrix(20) 0.003 nestedloop(12) 0.002 sieve(30) 0.002 strcat(200000) 0.001 ------------------------ Total 0.049
PHP 8.0.26
simple 0.005 simplecall 0.002 simpleucall 0.006 simpleudcall 0.008 mandel 0.037 mandel2 0.041 ackermann(7) 0.009 ary(50000) 0.003 ary2(50000) 0.002 ary3(2000) 0.019 fibo(30) 0.033 hash1(50000) 0.003 hash2(500) 0.004 heapsort(20000) 0.011 matrix(20) 0.012 nestedloop(12) 0.011 sieve(30) 0.006 strcat(200000) 0.002 ------------------------ Total 0.216
PHP 8.0.26 + JIT
simple 0.001 simplecall 0.000 simpleucall 0.000 simpleudcall 0.000 mandel 0.005 mandel2 0.006 ackermann(7) 0.004 ary(50000) 0.002 ary2(50000) 0.001 ary3(2000) 0.005 fibo(30) 0.009 hash1(50000) 0.002 hash2(500) 0.002 heapsort(20000) 0.004 matrix(20) 0.003 nestedloop(12) 0.002 sieve(30) 0.002 strcat(200000) 0.001 ------------------------ Total 0.049
PHP 7.4.33
simple 0.009 simplecall 0.002 simpleucall 0.007 simpleudcall 0.009 mandel 0.041 mandel2 0.043 ackermann(7) 0.009 ary(50000) 0.003 ary2(50000) 0.002 ary3(2000) 0.021 fibo(30) 0.032 hash1(50000) 0.004 hash2(500) 0.004 heapsort(20000) 0.011 matrix(20) 0.012 nestedloop(12) 0.015 sieve(30) 0.007 strcat(200000) 0.002 ------------------------ Total 0.232
I represented the execution time on a chart for each PHP versions (lower is better):
As you can see, PHP 8.2.0 is the fastest with 0.200 sec and PHP 7.4.33 is the slowest with 0.232 sec.
If you enable the JIT compiler (available only from 8.0.0) the execution time is reduced by 80%. That said, we know the JIT can be useful only for CPU-intensive applications.
Typically, a web application is not CPU-intensive and the usage of JIT can potentially degrade performance, giving the opposite effect.
If we compare the execution time of PHP 8.2.0 with other versions (without JIT), we discover that is:
- 15% faster than PHP 7.4.33;
- 8% faster than PHP 8.0.26;
- same of PHP 8.1.13;
The results show that the performance improvement of PHP 8.2 is quite significant (15%) compared with PHP 7.4.33.
Another important results is the performance trend, the PHP team did a great job improving the execution time on each release, this is not a simple task considering also the amount of new features added to the language.