- microtime: documentation ( source)
<?php
class Foo {
public $bar = 'bar';
}
$foo = new Foo;
$rounds = 1000000;
$start = microtime(true);
for($i=0; $i<$rounds; $i++) {
$var = $foo->bar;
}
echo (microtime(true) - $start);
echo "\n";
$start = microtime(true);
$refl = new ReflectionProperty('Foo', 'bar');
for($i=0; $i<$rounds; $i++) {
$var = $refl->getValue($foo);
}
echo (microtime(true) - $start);
echo "\n";
$start = microtime(true);
for($i=0; $i<$rounds; $i++) {
$var = (new ReflectionProperty('Foo', 'bar'))->getValue($foo);
}
echo (microtime(true) - $start);