3v4l.org

run code in 300+ PHP versions simultaneously
<?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";

preferences:
36.82 ms | 402 KiB | 5 Q