<?php
class A {
function foo($a, $b) {}
}
$max = 5*1e1;
$object = new A;
$t = microtime (true);
for ($i=0; $i<$max; $i++) {
$object->foo(1, 'foo');
}
echo $max.' x A::foo: '.round((microtime(true)-$t)*1e6, 2)." µs\n";
$t = microtime (true);
for ($i=0; $i<$max; $i++) {
call_user_func_array(array($object, 'foo'), array(1, 'foo'));
}
echo $max.' x call_user_func_array: '.round((microtime(true)-$t)*1e6, 2)." µs\n";
$t = microtime (true);
$ref = new ReflectionMethod($object, 'foo');
for ($i=0; $i<$max; $i++) {
$ref->invokeArgs($object, array(1, 'foo'));
}
echo $max.' x ReflectionMethod::invokeArgs: '.round((microtime(true)-$t)*1e6, 2)." µs\n";
$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'));
}
}
echo ($max/10).' x (10 x ReflectionMethod::invokeArgs): '.round((microtime(true)-$t)*1e6, 2)." µs\n";
preferences:
41.42 ms | 402 KiB | 5 Q