@
9 给你一步一步举个例子说明 第一步 函数实现不变,先运行$func() 再运行call_user_func($func);
...
$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;
输出结果 应该是 call_by_name exec time 11.320173978806
call_user_func exec time 10.576663970947
第二步, 函数实现不变,先运行call_user_func($func); 再运行 $func()
...
$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;
输出结果应该是
call_user_func exec time 11.387675046921
call_by_name exec time 10.002654075623
然后思考 函数实现与输出结果之间的相关性