测试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;
附运行结果
22s, 21s,时间差不多呀
页:
[1]