<?php
class A {
function foo($a, $b) {}
}
function row($name, $t) {
printf("%-40s %4.2s x 10 µs\n", $name, (microtime(true)-$t)*1e5);
}
$max = 5*1e1;
$object = new A;
$t = microtime (true);
for ($i=0; $i<$max; $i++) {
$object->foo(1, 'foo');
}
row($max.' x A::foo', $t);
$t = microtime (true);
for ($i=0; $i<$max; $i++) {
call_user_func_array(array($object, 'foo'), array(1, 'foo'));
}
row($max.' x call_user_func_array', $t);
$t = microtime (true);
$ref = new ReflectionMethod($object, 'foo');
for ($i=0; $i<$max; $i++) {
$ref->invokeArgs($object, array(1, 'foo'));
}
row($max.' x ReflectionMethod::invokeArgs', $t);
$t = microtime (true);
for ($j=0; $j<$max/10; $j++) {
$ref = new ReflectionMethod($object, 'foo');
for ($i=0; $i<10; $i++) {
$ref->invokeArgs($object, array(1, 'foo'));
}
}
row(($max/10).' x (10 x ReflectionMethod::invokeArgs)', $t);
preferences:
33.43 ms | 402 KiB | 5 Q