The interpreter of PHP is Zend Engine. Enter the Zend
directory of the source code package. This is the core part of PHP and is mainly responsible for the syntax implementation of PHP. , memory management and script compilation and running environment, etc.
Related tutorials: "PHP7"
/opt/softpackage/php-5.6.8/Zend /opt/softpackage/php-7.2.33/Zend /opt/softpackage/php-7.4.0/Zend
Find the test file bench.php
. There are a lot of test codes written in this file, such as
// 执行一百万次字符串 hallo 长度的计算 function simplecall() { for ($i = 0; $i < 1000000; $i++) strlen("hallo"); }
Execute /usr/local/php-5.6.8/bin/php bench.php
, the test results are as follows
simple 0.657 simplecall 1.980 simpleucall 1.712 simpleudcall 1.935 mandel 2.531 mandel2 2.860 ackermann(7) 1.101 ary(50000) 0.282 ary2(50000) 0.147 ary3(2000) 1.557 fibo(30) 5.309 hash1(50000) 0.362 hash2(500) 0.348 heapsort(20000) 1.564 matrix(20) 0.857 nestedloop(12) 0.796 sieve(30) 0.737 strcat(200000) 0.079 ------------------------ Total 24.813
Execute /usr/local/php -7.2.33/bin/php bench.php
, the test results are as follows
simple 0.089 simplecall 0.037 simpleucall 0.156 simpleudcall 0.169 mandel 0.483 mandel2 0.566 ackermann(7) 0.148 ary(50000) 0.186 ary2(50000) 0.020 ary3(2000) 0.237 fibo(30) 0.519 hash1(50000) 0.062 hash2(500) 0.048 heapsort(20000) 0.120 matrix(20) 0.121 nestedloop(12) 0.265 sieve(30) 0.129 strcat(200000) 0.035 ------------------------ Total 3.388
Execute /usr/local/php-7.4.0/bin/php bench.php
, The test results are as follows
simple 0.059 simplecall 0.016 simpleucall 0.033 simpleudcall 0.052 mandel 0.144 mandel2 0.135 ackermann(7) 0.042 ary(50000) 0.169 ary2(50000) 0.007 ary3(2000) 0.060 fibo(30) 0.126 hash1(50000) 0.031 hash2(500) 0.028 heapsort(20000) 0.080 matrix(20) 0.049 nestedloop(12) 0.075 sieve(30) 0.030 strcat(200000) 0.014 ------------------------ Total 1.151
Through comparison, it is found that the performance of PHP 7 has improved significantly. PHP 5 takes about 25 seconds to execute the test code, while PHP 7 does not exceed 4 seconds. In addition, PHP 7.4 has much better performance than PHP 7.2 improvement. Of course, the test results will be different in different test environments, but the performance improvement is definitely the same.
In addition, the Zend
directory also has a more complex test file micro_bench.php
. Interested partners can test it by themselves. If the stable version of PHP 8 is officially released, friends can also experience the performance of PHP 8 for themselves.
The above is the detailed content of About the performance comparison between PHP5 and PHP7. For more information, please follow other related articles on the PHP Chinese website!