Strange performance difference between Ubuntu and Macports versions of PHP
After doing some profiling on a personal pet project, I'm playing around with some stupid micro-optimisations. It's largely an experiment more than anything else so the things I'm tweaking don't actually need to be tweaked. It's still an interesting exercise though.
Anyway, I've come across a strange performance difference between my installation of PHP 5.3 on OS X through Macports and on Ubuntu from apt.
It seems that the following code shows a massive speed difference between the two different versions on OS X, but only a minuscule speed difference on Ubuntu.
$x = array(9);
// As per BarsMonster's comment, this ensures it runs for more
// than a second in order to avoid possible kernel scheduler differences
$count = 10000000;
$s = microtime(true);
for ($i=0;$i<$count;$i++) {
$q = is_string($x);
}
var_dump(microtime(true)-$s);
$s = microtime(true);
for ($i=0;$i<$count;$i++) {
// This is obviously only useful if you'll never need a string
// with 'Array' in it here
$q = (string)$x!='Array';
}
var_dump(microtime(true)-$s);
The output when running on OS X:
float(17.977133989334)
float(4.2555270195007)
The output when running on Ubuntu:
float(5.2112979888916)
float(3.4337821006775)
It doesn't surprise me to see that the figures for the hacked up cast version are pretty similar, but the is_string method is wildly different.
What can I attribute this to? If the performance varies so drastically from installation to installation for trivial type testing functions, how can I开发者_如何学Go trust the results of profiling using an OS that does not match my target deployment platform?
There is no difference in the times when running with APC on or off on both Ubuntu and OS X.
The Ubuntu installation was in the same PC as the OS X installation?
It may be something related to zts.
Try to configure it yourself with the same flags on both systems. There may be options enabled by default on ubuntu which are disabled by default in Ports.
I don't know exactly which, but your phpinfo() will tell. If it does not (maybe the phpinfo does not show, maybe it just shows a blank page; then maybe one of your systems is compiling with the Susoshin patch (or something else).
Please test for 1 second minumum, on sub-0.1 second timeframe kernel scheduler differences(and dozens of other reasons) might impact your results.
Check if you had any accelerators installed accidentally (APC, eAccelerator, e.t.c) - just compare phpinfo() from both instances and you will see.
精彩评论