PHP 8 能有多快?

2023-08-23 0 822

PHP-8将于今年底正式发布,其最更让人期盼的机能众所周知是JIT校对。让他们透过责任编辑来看一看此项机能对PHPJAVA的速率有什么样的负面影响?

PHP 8 能有多快?

译者 | Pedro Escudero

翻译者 | 弯月,白眉林 | 郭芮

下列为原文:

今年底,PHP-8将要正式发布。尽管那个主版有许多新机能,比如联手类别、动态回到和弱态射等,但最更让人期盼的改良却是JIT校对器。

从理论上讲,JIT处置PHPJAVA校对的形式能提升插件的速率。但让他们来看一看此种形式若想达至他们的期许。

请注意,在责任编辑中采用的PHP-8并非最后版。

具体来说,他们来撰写几段运转的标识符。我优先选择了冒泡次序,即使这是最糟的次序演算法,多于此种试验的这时候我就可以用那个次序演算法。

<?phpfunction bubble_sort($array){$start = microtime(true);do{$sw = false;for($i = 0, $size = count($array) 1; $i < $size; $i++){if( $array[$i] > $array[$i + 1] ){list( $array[$i + 1], $array[$i] ) =array($array[$i], $array[$i + 1]);$sw = true;}}}while($sw);$end = microtime(true);return $end $start;}$array = array(1000, -202, 3, 0, 2, 77, 5, -1, 4, 34, -203, 1, 0.5 , -3, 0.88,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -201,4000, 444, 0.99, -44, 4, 454443, -44444, 23, -201,5000, 444, 0.99, -44, 4, 4553, -4, 253, -201,6000, 444, 0.99, -44, 4, 443, -4, 2.3, -2.01,39000, 444, 0.99, -44, 4, 53, -4, 23, -201,309900, 444, 0.99, 23, 123, 453, -4, 23, -201,309900, 444, 0.99, -4.14, 4, 453, -4, 23, -201,309900, 444, 0.99, -4.44, 4, 453, -4, 23, -201,30500, 1144, 0.99, -4.4, 4, 453, -4, 23, -201,-3000, -444, 0.99, -44, 4, 453, -4, 23, -1,3000, 424, 0.19, -44, 4, 453, -4, 23, -21,300, 454, 0.99222, -44, 4, 453, -4, 23, -20.1,301110, 4442, 0.991, -44, 4, 453, -4, 2.443, -201,3033300, 33444, 0.49, -44, 4, 453, -4, 2.4443, -2010000);echo “\n”;echo bubble_sort($array);echo “\n”;?>

我知道那个JAVA撰写的并并非很好,尤其是中间那个讨厌的数组。我知道我可以生成一个随机数组。我也知道我可以从文件中读取那个数组。但是,我只想要一个不需要考虑其他因素的非常慢的冒泡演算法。我不希望那个基准试验中出现任何额外的干扰。

具体来说,他们在当前的PHP 7.4版中运转JAVA:

docker container run –rm -v $(pwd):/script/ php:7.4

php /script/bubble.php

运转100次得到的平均时间为0.10253500938416秒——还不错。

现在他们在PHP-8中运转,先不要激活JIT。

docker container run –rm -v $(pwd):/script/ martinpham/php8:

fpm-extra-alpine php /script/bubble.php

同样运转100次的平均时间为0.098223924636841秒。老实说,那个提升不怎么明显。

下面,他们来试验期盼已久的JIT:

docker container run –rm -v $(pwd):/script/

keinos/php8-jit php /script/bubble.php

平均运转时间为0.053637981414795秒!JIT确实很惊

我想从更多的角度来对比,因此我采用了2009年的PHP-5.3版来运转这段标识符。

docker container run –rm -v $(pwd):/script/ php:5.3

php /script/bubble.php

平均花费了0.64574003219604秒。比激活了JIT的PHP-8满了0.5921020508(下降了-1,103.88)!我的天,2009年的这时候他们是怎么过来的?

PHP 8 能有多快?

注意:

优先选择的JAVA多于一个纯粹的冒泡演算法。当然,你可以尝试其他标识符,比如旅行推销员问题或二叉树。结果应该都差不多。

正如我在文中提到的那样,那个基准试验运转的PHP-8版并非最后版,因此可能最后的发行版会增添其他改良

我在试验结果中保留了许多位小数,尽管看着很罗嗦,但我只是想尽可能做到精确。

在基准试验中,我采用keinos和martinpham的docker镜像。其实还有许多其他工具,你可以优先选择自己喜欢的尝试一下。

我运转试验的笔记本电脑的配置为:Linux Manjaro、3 GHz Intel Core i5、32 GB RAM。在其他配置下,具体的数字可能会有所不同,但是我相信改良结果都很相似。

原文:

https://levelup.gitconnected.com/how-fast-is-php-8-going-to-be-f7fdc111cd6

译者:Pedro Escudero,工程副总裁@zinio.com。

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务