Contents
  1. 1. 循环1千万次
  2. 2. 循环1亿次
  3. 3. 结论

以下记录简单的for循环性能对比

循环1千万次

1
2
3
4
5
6
<?php
for ($i = 0; $i < 10000000; $i++) {
mt_rand(0, 100);
}
?>

结果

1
2
3
4
5
6
joelhy@archlinux: /tmp $ time php for.php
php for.php 4.12s user 0.00s system 99% cpu 4.124 total
joelhy@archlinux: /tmp $ time php7 for.php
php7 for.php 0.45s user 0.00s system 99% cpu 0.455 total
joelhy@archlinux: /tmp $ time hhvm for.php
hhvm for.php 0.19s user 0.02s system 90% cpu 0.228 total

循环1亿次

1
2
3
4
5
<?php
for ($i = 0; $i < 100000000; $i++) {
mt_rand(0, 100);
}
?>

结果

1
2
3
4
5
6
joelhy@archlinux: /tmp $ time php for.php
php for.php 42.08s user 0.00s system 99% cpu 42.093 total
joelhy@archlinux: /tmp $ time php7 for.php
php7 for.php 4.56s user 0.01s system 99% cpu 4.574 total
joelhy@archlinux: /tmp $ time hhvm for.php
hhvm for.php 1.07s user 0.02s system 97% cpu 1.118 total

结论

就for循环而论,PHP 7相对PHP5.6有极大的性能提升, 不过执行速度仍然逊于HHVM 3.11。

Contents
  1. 1. 循环1千万次
  2. 2. 循环1亿次
  3. 3. 结论