为什么php5.3.8比5.3.7慢10倍?

leo*_*eon 1 php

我刚刚使用dotdeb.org的apt源升级到php 5.3.8.

php性能的测试结果非常糟糕.

我在安装php5.3.8之前和之后用这个脚本测试.似乎运行相同的代码将花费10倍于php5.3.8的时间而不是php5.3.7.

测试PHP脚本:

<?php
//test float
function test_float() {
    $t = pi();
    $timeStart = gettimeofday();

    for($i = 0; $i < 3000000; $i++) {
        sqrt($t);
    }

    $timeEnd = gettimeofday();
    $time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
    $time = round($time, 3)."s";
    return $time;
}

echo "php version:" , phpversion(), "\n";
echo "call sqrt()  3,000,000 times will cost ", test_float(), "\n";

?>
Run Code Online (Sandbox Code Playgroud)

测试结果:

php version:5.3.3-7+squeeze3
call sqrt()  3,000,000 times will cost 1.369s
php version:5.3.3-7+squeeze3
call sqrt()  3,000,000 times will cost 1.095s
php version:5.3.3-7+squeeze3
call sqrt()  3,000,000 times will cost 1.072s
php version:5.3.8-1~dotdeb.2
call sqrt()  3,000,000 times will cost 10.644s
php version:5.3.8-1~dotdeb.2
call sqrt()  3,000,000 times will cost 10.567s
php version:5.3.8-1~dotdeb.2
call sqrt()  3,000,000 times will cost 10.343s
Run Code Online (Sandbox Code Playgroud)

Arn*_*anc 5

5.3.8版本可能已使用调试选项编译,或者没有编译器优化.

或者你可能在PHP 5.3.7中添加了一些缓慢的扩展,这在PHP 5.3.7中没有启用,比如xdebugsuhosin.

我敢打赌第二个解决方案.

  • 比较输出php -m.(已加载模块列表.)
  • 尝试运行基准测试php -n(运行PHP而不加载任何ini设置文件)