本文 |
set_time_limit(0);
$cnt = 1000000;
class A {
public function __toString() {
return '';
}
}
$a = new A();
$b = 'afdafdsafda';
for ($i = 0; $i < $cnt; $i++) {
// warmup loop
$x = 1 + 1;
$y = $x;
}
$st = getmicrotime();
print "warmup ".(getmicrotime() - $st)."\n";
$st = getmicrotime();
for ($i = 0; $i < $cnt; $i++) {
$x = (is_callable([$a, '__toString'], false) ? 1 : 2);
$y = (is_callable([$b, '__toString'], false) ? 3 : 4);
}
print "first ".(getmicrotime() - $st)."\n";
$st = getmicrotime();
for ($i = 0; $i < $cnt; $i++) {
$x = ((is_object($a) && method_exists($a, '__toString')) ? 1 : 2);
$y = ((is_object($b) && method_exists($b, '__toString')) ? 3 : 4);
}
var_dump($x, $y);
print "second ".(getmicrotime() - $st)."\n";
exit;
warmup 0.0001070499420166
first 21.014949083328
second 51.076045036316 |