call_user_funcの履歴
例
$func = 'callback'; $arg1 = 'Hello'; $arg2 = 'World'; $result = call_user_func($func, $arg1, $arg2); echo $result; function callback($arg1, $arg2){ return $arg1 . ' ' . $arg2; }
> Hello World
Becnmark
test code
require_once('Benchmark/Timer.php'); $b = new Benchmark_Timer(); $b->start(); $func = 'concat'; $arg1 = 'Hello'; $arg2 = 'World'; for ($i = 0; $i < 100000; $i++){ concat($arg1, $arg2); } $b->setMarker(1); for ($i = 0; $i < 100000; $i++){ call_user_func($func, $arg1, $arg2); } $b->setMarker(2); $st = new str(); for ($i = 0; $i < 100000; $i++){ call_user_func(array($st, 'concat'), $arg1, $arg2); } $b->display(); function concat($arg1, $arg2){ return $arg1 . ' ' . $arg2; } class str{ function concat($arg1, $arg2){ return $arg1 . ' ' . $arg2; } }
result
---------------------------------------------------- marker time index ex time perct ---------------------------------------------------- Start 1178772754.67023400 - 0.00% ---------------------------------------------------- 1 1178772755.06544500 0.395211 20.20% ---------------------------------------------------- 2 1178772755.72854600 0.663101 33.90% ---------------------------------------------------- Stop 1178772756.62629900 0.897753 45.90% ---------------------------------------------------- total - 1.956065 100.00% ----------------------------------------------------