- microtime: documentation ( source)
<?php
class Foo {
private $spec;
private $msg;
public function __construct($spec, $msg = null) {
$this->spec = $spec;
$this->msg = $msg;
}
public static function new_instance($spec, $msg = null) {
return new static($spec, $msg);
}
}
const ITERATIONS = 100000;
$time1 = -microtime(true);
for ($i = 0; $i < ITERATIONS; ++$i) {
Foo::new_instance(array(), 'foo');
}
$time1 += microtime(true);
echo "direct function call took $time1 seconds\n";
$time2 = -microtime(true);
for ($i = 0; $i < ITERATIONS; ++$i) {
call_user_func_array(array('Foo', 'new_instance'), array(array(), 'foo'));
}
$time2 += microtime(true);
echo "call_user_func_array() took $time2 seconds\n";
echo "difference: ", $time2 / $time1, "\n";