- microtime: documentation ( source)
- number_format: documentation ( source)
<?php
class Foo
{
private $bar;
public function setBar($bar)
{
$this->bar = $bar;
}
public function getBar()
{
return $this->bar;
}
}
$n = 10000;
$t = microtime(true);
$foo = new Foo();
for ($i = 0; $i < $n; $i++) {
$foo->setBar("foo");
$foo->getBar();
}
echo number_format(microtime(true) - $t, 6) . "\n";
$t = microtime(true);
$reflClass = new ReflectionClass('Foo');
$property = $reflClass->getProperty('bar');
$property->setAccessible(true);
$foo = new Foo();
for ($i = 0; $i < $n; $i++) {
$property->setValue($foo, "bar");
$property->getValue($foo);
}
echo number_format(microtime(true) - $t, 6) . "\n";