3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { protected $a; public function getA() { return $this->a; } public function setA($a) { $this->a = $a; } } $test = new Test; $test->setA("foo"); $someArray = array(); $start_time = MICROTIME(TRUE); for ($i=1; $i<=10000; $i++) { if ('' !== ($foo = $test->getA())) { $someArray[] = $foo; } } $stop_time = MICROTIME(TRUE); $time = $stop_time - $start_time; echo "Elapsed time was $time seconds."; $start_time2 = MICROTIME(TRUE); for ($i=1; $i<=10000; $i++) { if ('' !== ($foo = $test->getA())) { $someArray[] = $foo; } unset($foo); } $stop_time2 = MICROTIME(TRUE); $time2 = $stop_time2 - $start_time2; echo "Elapsed time was $time2 seconds."; $start_time3 = MICROTIME(TRUE); for ($i=1; $i<=10000; $i++) { if ('' !== $test->getA()) { $someArray[] = $test->getA(); } } $stop_time3 = MICROTIME(TRUE); $time3 = $stop_time3 - $start_time3; echo "Elapsed time was $time3 seconds.";

preferences:
35.05 ms | 402 KiB | 5 Q