开发者

Why is php5.3.8 10 times slower than 5.3.7?

I just upgraded to php 5.3.8 using dotdeb.org's apt source.

The test result of php performance is very bad.

I test with this script, before and after install php5.3.8. It seems to run the same code will take 10 times time in php5.3.8 than in php5.3.7.

Test php script:

<?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";

?>

Test result:

php version:5.3.3-7+squeeze3
call sqrt()  3,000,000 times will cost 1.369s
php ve开发者_StackOverflow社区rsion: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


The 5.3.8 version may have been compiled with debug options, or without compiler optimisations.

Or you may have added some slow extension in PHP 5.3.8 that's not enabled in PHP 5.3.7, like xdebug or suhosin.

I would bet for the second solution.

  • Compare the output of php -m. (List of loaded modules.)
  • Try running the benchmark with php -n (runs PHP without loading any ini settings file)


That does not matter anyway, as there is a critical security bug in 5.3.7. Function crypt returns only salt. So, no matter slower it or faster, it's not recommended to use 5.3.7


Benchmarks and performance analysis should always be done on real code, the one you're trying to optimize the performance.

In fact, maybe it's only the sqrt() function that is slower, and 99% of all the function 3 times faster. I think the problem comes from you benchmark.

Also, please check that you compiled php the same way on both version, on the same machine, same php.ini etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜