在研究 PHP 7 及其变化和性能时,我遇到了一个在 PHP 5 中比在 PHP 7 中更快的函数:metaphone()
. 我测试的所有其他函数在 PHP 7 中都要快得多。
我找不到有关此的任何信息,而且似乎没有人遇到过这个,这让我认为问题出在我的最后(服务器配置或其他东西)。但是,据我所知,两个 PHP 版本的配置文件(php.ini)是相同的(都是 x86)。
我在 IIS 中使用 PHP 5 和 PHP 7 运行了以下脚本:
<?php
$str = "test";
$count = 1000000;
$time_start = microtime(true);
for ($i=0; $i < $count; $i++) {
metaphone($str);
}
echo 'Seconds: ' . number_format(microtime(true) - $time_start, 2);
结果:
PHP 5.5.30:0.97秒
PHP 7.0.0:2.98秒
我希望有人可以在他们的服务器上测试这个。如果你得到相同的结果,为什么在这种情况下 PHP 7 比 PHP 5 慢?如果没有,我的问题可能是什么?
编辑:
我只是注意到了这些功能strtoupper()
,而且strtolower
PHP 7 中的速度也比 PHP 5 中慢。