PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Proof that PHP 5.4 is Twice as Fast as PHP 5.3

Note: This article was originally published at Planet PHP on 14 June 2012.
Planet PHP

So recently I was working on some benchmarks for different versions of PHP, because I heard that PHP 5.4 is "faster" and since I'm a data geek I want to know how much faster! Now, PHP 5.4 is, in general, faster than PHP 5.3 but not twice as fast* unless you pick a use case which has been particularly optimised.

My first attempt at benchmarking the two versions produced this:


This was a surprise to me; was PHP 5.4 really so much faster??

It turns out that it isn't, and my mistake was to pick a very simple script which only does one thing - and that thing is something that actually was vastly improved between versions! I have a script that runs the same piece of code lots of times and does some crude timings with that - so these numbers are only useful as a relative comparison; I'm just running this stuff on my laptop.

The script:

$r = 10 * 1000 * 1000; $start = microtime(true); A while($r-- 0) { new StdClass(); } A $finish = microtime(true); echo "time taken: " . ($finish - $start) . "\n";

I ran each test five times and averaged the results (original data: thrown into a gist if you want it).

The moral of this story is: you can prove anything you want with statistics! I'm assembling a more varied script for some rather more useful benchmarks, but just look at how much faster it is to instantiate an object in PHP 5.4! Many thanks to everyone who contributes to the PHP project, the language continues to evolve and improve in so many ways, and I am grateful!

* Apologies for the inflammatory blog post title, but those were my exact words when I got this result set.

Lorna is an independent web development consultant, writer and trainer, open source project lead and community evangelist. This post was originally published at LornaJane