PHP7 Showing 3x Performance Gains Over PHP5 In Computational Tests

I’ve been upgrading my development systems from Fedora 24 to 25, getting PHP 7.0 in the process, replacing PHP 5.6. Much to my delight, the first tests with a specific computationally-oriented workload that I run are showing impressive performance improvements.

php7

I have a custom authored PHP CLI application for doing walk forward stock trading simulations on historical EOD data (the details of which aren’t important here). The computationally intensive part makes heavy use of SplFixedArray, ordinary arrays, and a variety of built in array functions.

You’re going to ask, why on earth did you write such a thing in PHP. Well, because at the time that I wrote it, in 2008-2011, that was what I was coding in. I wouldn’t write it in PHP if I had to do it over again. It’s a little over 5,000 lines of code in 20 modules though, and it works just fine, so that’s not happening.

Back to the point: The program reports its total memory consumption and processing performance in number of simulations run per second as it works, which gives me precise, consistent data to compare its performance characteristics under PHP 5.6 versus PHP 7.0, when tasking each with the same workload on the same data. This makes for a nice end to end test of PHP CLI’s processing speed and memory usage when managing a whole mess of SplFixedArray’s, normal arrays and array functions. Is it a very well controlled or designed test? No, not really. It’s more of a compound, real world benchmark, of the kind you sometimes see folded into benchmarking suites.

OK, let’s look at the numbers:

PHP version  |  Peak memory use  |  Simulation speed
-------------+-------------------+--------------------
PHP 5.6      |       477MB       |       79/sec
PHP 7.0      |       171MB       |      227/sec
-------------+-------------------+--------------------
Gain /       |  2.8x less or     |  2.9x faster or
Reduction    |  36% of the usage |  35% of the runtime

Apologies for my ridiculously antiquated ASCII table. I’m getting basically 3x gains in both departments, which pleases me greatly, after having been promised 2x-2.5x in everything I’d read. The processing speed improvements actually jibe very well with what Michael Larabel reported over on Phoronix several days ago, for, obviously, a completely different but also compound workload initiated from the CLI.

Now, nobody does this kind of thing with these tools. Mine is a totally esoteric use case, I know. The PHP use case that most users care about wouldn’t be something like this at all, it’d be on the web server.

At the risk of upsetting anyone, realistically for ordinary web applications (barring specific circumstances) the interpreter isn’t the speed bottleneck. It certainly helps – we do like things to go fast. But the speed bottleneck is almost always accessing storage / database. Memory consumption, though, is a very real issue on web servers, and PHP7 should help that in a meaningful way. Field reports are liable to vary. Tumblr Engineering came out with a report last month telling that they saw prominent gains in both (CPU and memory).

For my application anyway, the bottom line is I can model and evaluate three times as many scenarios in the space of the same time and memory constraints. I haven’t benchmarked my web servers but the idea is they’re zipping along that much faster and more efficiently on PHP7 too. So, hat tip to the PHP developers for their impressive work.

Resources

PHP 7 Release Announcement

Phoronix: “PTS: PHP 7.1 vs. PHP 7.0 vs. HHVM Benchmarks”

Tumblr Engineering: “PHP 7 at Tumblr”