Member-only story
How fast is PHP-8 going to be?
PHP-8 is going to be released at the end of this year, and one of its most exciting features is JIT compilation. Let’s see how it improves the speed of a PHP script.
At the end of this year, PHP-8 will be a reality. While this major version is coming with multiple new features like union types, static return, and weak maps, the most anticipated improvement is the JIT compiler.
In theory, JIT will increase the speed of an application due to how it handles the compilation of the PHP scripts (I am oversimplifying). But let’s see if the approach fulfills our expectations
Note that the version of PHP-8 that I am going to use is not final.
First of all, let’s define the code to run. I choose the bubble sort because it is the worst sorting method, and I can only employ it for exercises like this.
Source code in https://gist.github.com/PedroEscudero/b64ea7409c0cc483c44f0773b6aebbdb
I am aware that the script is not beautiful with that nasty array over there in the middle. I know that I can generate a random array. I also know that I can read it from a file. However, I just want a slow bubble that has not to deal with other considerations. I don’t want any extra noise in this benchmark.
First, let’s run the script it in the current version of PHP the 7.4
docker container run --rm -v $(pwd):/script/ php:7.4 php /script/bubble.php
After running it 100 times, the average time that I had was 0.10253500938416 seconds. Not bad.
Now we go with PHP-8 without JIT activated.
docker container run --rm -v $(pwd):/script/ martinpham/php8:fpm-extra-alpine php /script/bubble.php
Again, after 100 runs, I had an average time of 0.098223924636841 seconds. To be honest, the improvement is not very impressive.
But we are here to test the star feature, the shiny and amazing JIT:
docker container run --rm -v…