Szopen Xiao

PHP 8-dev, PHP 7.2, PHP 5.6 基准测试比较

2019-07-31

测试脚本是 PHP5.6.20 中的 <PHP-5.6.20_SOURCE>/Zend/bench.php<PHP-5.6.20_SOURCE>/Zend/micro_bench.php

  • 以下是PHP 7.2.20 (cli)( NTS )的测试结果:
    1. 执行bench.php
        $ php <PHP-5.6.20_SOURCE>/Zend/bench.php
        simple             0.023
        simplecall         0.007
        simpleucall        0.023
        simpleudcall       0.023
        mandel             0.086
        mandel2            0.105
        ackermann(7)       0.020
        ary(50000)         0.005
        ary2(50000)        0.004
        ary3(2000)         0.047
        fibo(30)           0.071
        hash1(50000)       0.010
        hash2(500)         0.009
        heapsort(20000)    0.023
        matrix(20)         0.026
        nestedloop(12)     0.046
        sieve(30)          0.016
        strcat(200000)     0.005
        ------------------------
        Total              0.550
      
    2. 执行micro_bench.php
        empty_loop         0.030
        func()             0.091    0.061
        undef_func()       0.101    0.071
        int_func()         0.061    0.031
        $x = self::$x      0.090    0.060
        self::$x = 0       0.078    0.048
        isset(self::$x)    0.088    0.058
        empty(self::$x)    0.084    0.054
        $x = Foo::$x       0.064    0.034
        Foo::$x = 0        0.055    0.025
        isset(Foo::$x)     0.064    0.034
        empty(Foo::$x)     0.065    0.035
        self::f()          0.106    0.077
        Foo::f()           0.090    0.061
        $x = $this->x      0.059    0.030
        $this->x = 0       0.044    0.015
        $this->x += 2      0.086    0.056
        ++$this->x         0.062    0.032
        --$this->x         0.066    0.036
        $this->x++         0.079    0.049
        $this->x--         0.070    0.040
        isset($this->x)    0.078    0.048
        empty($this->x)    0.084    0.054
        $this->f()         0.095    0.065
        $x = Foo::TEST     0.078    0.048
        new Foo()          0.223    0.194
        $x = TEST          0.054    0.024
        $x = $_GET         0.086    0.056
        $x = $GLOBALS['v'] 0.120    0.090
        $x = $hash['v']    0.102    0.072
        $x = $str[0]       0.070    0.040
        $x = $a ?: null    0.067    0.038
        $x = $f ?: tmp     0.070    0.040
        $x = $f ? $f : $a  0.056    0.026
        $x = $f ? $f : tmp 0.062    0.032
        ------------------------
        Total              2.778
      
  • 以下是PHP 8.0.0-dev (cli)( NTS )开启JIT的测试结果:
    1. 执行bench.php
        simple             0.017
        simplecall         0.005
        simpleucall        0.004
        simpleudcall       0.004
        mandel             0.025
        mandel2            0.035
        ackermann(7)       0.015
        ary(50000)         0.004
        ary2(50000)        0.003
        ary3(2000)         0.029
        fibo(30)           0.043
        hash1(50000)       0.010
        hash2(500)         0.007
        heapsort(20000)    0.016
        matrix(20)         0.016
        nestedloop(12)     0.018
        sieve(30)          0.010
        strcat(200000)     0.003
        ------------------------
        Total              0.263
      
    2. 执行micro_bench.php
        empty_loop         0.035
        func()             0.018    -0.017
        undef_func()       0.019    -0.016
        int_func()         0.019    -0.016
        $x = self::$x      0.079    0.044
        self::$x = 0       0.068    0.033
        isset(self::$x)    0.073    0.038
        empty(self::$x)    0.073    0.038
        $x = Foo::$x       0.045    0.010
        Foo::$x = 0        0.036    0.001
        isset(Foo::$x)     0.031    -0.004
        empty(Foo::$x)     0.038    0.003
        self::f()          0.019    -0.016
        Foo::f()           0.019    -0.016
        $x = $this->x      0.043    0.008
        $this->x = 0       0.035    0.000
        $this->x += 2      0.061    0.026
        ++$this->x         0.050    0.015
        --$this->x         0.050    0.015
        $this->x++         0.050    0.015
        $this->x--         0.052    0.017
        isset($this->x)    0.050    0.015
        empty($this->x)    0.052    0.017
        $this->f()         0.072    0.037
        $x = Foo::TEST     0.068    0.033
        new Foo()          0.167    0.132
        $x = TEST          0.040    0.005
        $x = $_GET         0.084    0.049
        $x = $GLOBALS['v'] 0.106    0.071
        $x = $hash['v']    0.019    -0.016
        $x = $str[0]       0.020    -0.015
        $x = $a ?: null    0.019    -0.016
        $x = $f ?: tmp     0.020    -0.015
        $x = $f ? $f : $a  0.019    -0.016
        $x = $f ? $f : tmp 0.020    -0.015
        ------------------------
        Total              1.669
      
  • 以下是PHP 5.6.40 (cli) (NTS)的测试结果:
    1. 执行bench.php
        simple             0.042
        simplecall         0.018
        simpleucall        0.079
        simpleudcall       0.080
        mandel             0.135
        mandel2            0.179
        ackermann(7)       0.072
        ary(50000)         0.018
        ary2(50000)        0.016
        ary3(2000)         0.113
        fibo(30)           0.250
        hash1(50000)       0.028
        hash2(500)         0.023
        heapsort(20000)    0.056
        matrix(20)         0.065
        nestedloop(12)     0.075
        sieve(30)          0.074
        strcat(200000)     0.008
        ------------------------
        Total              1.329
      
    2. 执行micro_bench.php
        empty_loop         0.088
        func()             0.267    0.179
        undef_func()       0.268    0.180
        int_func()         0.223    0.135
        $x = self::$x      0.207    0.119
        self::$x = 0       0.187    0.099
        isset(self::$x)    0.179    0.091
        empty(self::$x)    0.188    0.100
        $x = Foo::$x       0.178    0.090
        Foo::$x = 0        0.166    0.078
        isset(Foo::$x)     0.165    0.077
        empty(Foo::$x)     0.175    0.087
        self::f()          0.312    0.224
        Foo::f()           0.281    0.193
        $x = $this->x      0.183    0.094
        $this->x = 0       0.222    0.134
        $this->x += 2      0.195    0.107
        ++$this->x         0.175    0.087
        --$this->x         0.170    0.082
        $this->x++         0.206    0.118
        $this->x--         0.181    0.093
        isset($this->x)    0.181    0.093
        empty($this->x)    0.191    0.103
        $this->f()         0.315    0.227
        $x = Foo::TEST     0.176    0.088
        new Foo()          0.489    0.401
        $x = TEST          0.142    0.054
        $x = $_GET         0.182    0.094
        $x = $GLOBALS['v'] 0.247    0.159
        $x = $hash['v']    0.192    0.104
        $x = $str[0]       0.239    0.151
        $x = $a ?: null    0.172    0.084
        $x = $f ?: tmp     0.232    0.144
        $x = $f ? $f : $a  0.173    0.085
        $x = $f ? $f : tmp 0.224    0.136
        ------------------------
        Total              7.368
      
  • 通过以上测试结果,以PHP5.6为基准进行比较后,得出以下结论

    项目 PHP 5.6 PHP 7.2 PHP 8.0-dev
    总体 100% 38% 22%
    函数调用 100% 34% 8%
    字符串连接 100% 62% 37.5%
    创建对象 100% 48% 32.9%
    对象方法调用 100% 28.6% 16%

    也就是说,PHP7.2PHP5.6提升了60%左右, PHP 8.07.2提升了40%左右

comments powered by Disqus