PHP 8 性能究竟有多大的提升?

今年年底,PHP-8即将发布。虽然这个主版本有很多新功能,例如联合类型、静态返回和弱映射等,但最令人期待的改进还是JIT编译器。

从理论上讲,JIT处理PHP脚本编译的方式能够提高应用程序的速度。但让我们来看看这种方法能否达到我们的期望。

请注意,在本文中使用的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";?>

郑重声明:本文版权包含图片归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们(delete@yzlfxy.com)修改或删除,多谢。

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

留言与评论(共有 0 条评论)
昵称:
匿名发表
   
验证码: