简体   繁体   English

Ubuntu和Macports版本的PHP之间存在奇怪的性能差异

[英]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. 无论如何,我在OS X上通过Macports安装PHP 5.3和从apt安装Ubuntu时遇到了奇怪的性能差异。

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. 似乎以下代码显示了OS X上两个不同版本之间的巨大速度差异,但在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: 在OS X上运行时的输出:

float(17.977133989334)
float(4.2555270195007)

The output when running on Ubuntu: 在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. 看到被黑客攻击的版本的数字非常相似并不令我感到惊讶,但是is_string方法却截然不同。

What can I attribute this to? 我可以将此归因于什么? If the performance varies so drastically from installation to installation for trivial type testing functions, how can I 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. 在Ubuntu和OS X上打开或关闭APC的时间没有区别。

The Ubuntu installation was in the same PC as the OS X installation? Ubuntu安装与OS X安装在同一台PC上?

It may be something related to zts. 它可能与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. 默认情况下,在ubuntu上可能启用了选项,默认情况下在Ports中禁用这些选项。

I don't know exactly which, but your phpinfo() will tell. 我不确切知道哪个,但你的phpinfo()会告诉我。 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). 如果没有(也许phpinfo没有显示,也许它只是显示一个空白页;那么你的系统之一可能正在编译Susoshin补丁(或其他)。

  1. Please test for 1 second minumum, on sub-0.1 second timeframe kernel scheduler differences(and dozens of other reasons) might impact your results. 请测试最小1秒,低于0.1秒的时间帧内核调度程序差异(以及许多其他原因)可能会影响您的结果。

  2. Check if you had any accelerators installed accidentally (APC, eAccelerator, etc) - just compare phpinfo() from both instances and you will see. 检查您是否意外安装了任何加速器(APC,eAccelerator等) - 只需比较两个实例中的phpinfo(),您就会看到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM