Chinaunix
标题:
测试php代码,越在前面运行的越耗时
[打印本页]
作者:
yakczh_cu
时间:
2014-06-16 12:07
标题:
测试php代码,越在前面运行的越耗时
本帖最后由 yakczh_cu 于 2014-06-16 12:32 编辑
test1.php
<?php
function test(){
$i=100;
$arr=array();
do { array_push($arr,$i); }while ($i--);
}
$func='test';
define('REPEAT',10000*10);
$cnt=REPEAT;
$start=microtime(true);
do { $func(); } while ($cnt--);
$end=microtime(true);
echo "\ncall_by_name exec time " ,$end-$start;
$cnt=REPEAT;
$start=microtime(true);
do { call_user_func($func); }while ($cnt--);
$end=microtime(true);
echo "\ncall_user_func exec time " ,$end-$start;
?>
复制代码
test2.php
<?php
function test(){
$i=100;
$arr=array();
do { array_push($arr,$i); }while ($i--);
}
$func='test';
define('REPEAT',10000*10);
$cnt=REPEAT;
$start=microtime(true);
do { call_user_func($func); }while ($cnt--);
$end=microtime(true);
echo "\ncall_user_func exec time " ,$end-$start;
$cnt=REPEAT;
$start=microtime(true);
do { $func(); } while ($cnt--);
$end=microtime(true);
echo "\ncall_by_name exec time " ,$end-$start;
复制代码
作者:
yakczh_cu
时间:
2014-06-16 12:14
附运行结果
run.jpg
(0 Bytes, 下载次数: 20)
下载附件
2014-06-16 12:14 上传
作者:
action08
时间:
2014-08-12 07:48
22s, 21s,时间差不多呀
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2