- microtime: documentation ( source)
<?php
class Foo
{
protected $bar = 'baz';
public function getBar()
{
return $this->bar;
}
}
$foo = new Foo;
$time = microtime(true);
for ($i = 0; $i <= 10000; $i++) {
$ref = new ReflectionClass($foo);
$property = $ref->getProperty('bar');
$property->setAccessible(true);
$property->getValue($foo);
}
echo "REFLECTION: ", microtime(true) - $time, PHP_EOL;
$time = microtime(true);
for ($i = 0; $i <= 10000; $i++) {
$foo->getBar();
}
echo "GETTER: ", microtime(true) - $time, PHP_EOL;