3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ArrayTester { const TEST_LOOP_SIZE = 100000; public function go() { $start = microtime(true); for($a = 0; $a<=self::TEST_LOOP_SIZE;++$a) { $test = $this->getTest(); $someVal = $test[$a]; } echo 'Pass by copy: ' . (microtime(true) - $start) . ' sec<br>'; $start = microtime(true); for($a = 0; $a<=self::TEST_LOOP_SIZE;++$a) { $test = &$this->getTestByRef(); $someVal = $test[$a]; } echo 'Pass by reference: ' . (microtime(true) - $start) . ' sec<br>'; } private $_test; private function getTest() { if(!$this->_test) { for($a = 0; $a<=self::TEST_LOOP_SIZE;++$a) { $this->_test[$a]=md5($a); } } return $this->_test; } private $_testByRef; private function &getTestByRef() { if(!$this->_testByRef) { for($a = 0; $a<=self::TEST_LOOP_SIZE;++$a) { $this->_testByRef[$a]=md5($a); } } return $this->_testByRef; } } $tester = new ArrayTester(); $tester->go();

preferences:
33.56 ms | 402 KiB | 5 Q