- microtime: documentation ( source)
<?php
class Foo {
public function bar() {
return "";
}
}
$ts = microtime(true);
for ($i=1; $i<=10000; $i++) {
$c = new Foo();
echo $c->bar();
unset ($c);
}
$tt = microtime(true);
$t1 = $tt-$ts;
unset($ts, $tt);
echo "Variable Instantiation takes {$t1} seconds\n";
$ts = microtime(true);
for ($i=1; $i<=10000; $i++) {
echo (new Foo())->bar();
}
$tt = microtime(true);
$t2 = $tt-$ts;
unset($ts, $tt);
echo "Magic Instantiation takes {$t2} seconds\n";
echo "\n";