3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestFixedArray extends SplFixedArray { private $_elements; public function __sleep() { $arr = (array)$this; unset($arr["\0TestFixedArray\0_elements"]); $this->_elements = $arr; $this->setSize(0); $arr = null; return array('_elements'); } public function __wakeup() { $size = count($this->_elements); $this->setSize($size); for($i = 0; $i < $size; $i++) { $this[(int)$i] = (int)$this->_elements[$i]; } $this->_elements = null; unset($this->_elements); } } $n = 100000; $t = microtime(true); $m = memory_get_usage(true); if(file_exists('cache.txt')) { echo 'Unserialize' . PHP_EOL; $content = file_get_contents('cache.txt'); $a = igbinary_unserialize($content); //$a = unserialize($content); $content = null; } else { echo 'Serialize' . PHP_EOL; //$a = new SplFixedArray($n); $a = new TestFixedArray($n); //$a = array(); for($i = 0; $i < $n; $i++) { $a[(int)$i] = (int)$i; } if(!file_exists('cache.txt')) { var_dump('serialize'); //file_put_contents('cache.txt', serialize($a)); file_put_contents('cache.txt', igbinary_serialize($a)); } } echo 'Peak: ' . memory_get_peak_usage(true) . PHP_EOL; echo 'Usage: ' . (memory_get_usage(true) - $m) . PHP_EOL; echo 'Time: ' . (microtime(true) - $t) . PHP_EOL;

preferences:
26.34 ms | 411 KiB | 5 Q