3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ringBuffer implements ArrayAccess { private $data; private $current = 0; public $size; public function __construct($sz=10) { $this->size = $sz; foreach(range(1, $sz) as $k=>$v) { /* s: whether this node is set; d: whether this node is “dirty” (has been read since it was last set); v: the value */ $this->data[$k] = array('s' => false, 'd' => false, 'v' => NULL); } } public function offsetGet($key) { if (! is_int($key)) $this->throwEx(array(“offset '%s' must be an integer, not %s”, $key, gettype($key))); if ($key > $this->size) $key %= $this->size; if (!isset($this->data[$key])) return false; if (!$this->data[$key]['s']) return false; $this->data[$key]['d'] = false; return $this->data[$key]['v']; } public function offsetExists($key) { if (! is_int($key)) throw new Exception(); if ($key > $this->size) return $this->data[$key]['s']; } public function offsetUnset($key) { $this->data[$key]['s'] = false; $this->data[$key]['v'] = NULL; } private function throwEx() { $args = func_get_args(); if (is_array($args0)) { $msg = call_user_func_array('sprintf', $args0); } throw new Exception($msg); } public function push($value) { if ($this->current >= $this->size) $this->current %= $this->size; $this->data[$this->current] = array('s'=>true, 'd'=>true, 'v' => $value); $this->current++; return $value; } } $a = new ringBuffer(2); $a->push(“foo”); $a->push(“bar”); $a->push(“baz”); var_dump($a); /* Will throw an exception because you can't directly set indices in a ringBuffer */ $a0 = 'foo'; /* Will throw an exception because ringBuffer indices must be ints */ var_dump($a['foo']); var_dump($a[1.0]);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.280.0110.05812.39
5.4.270.0100.05412.38
5.4.260.0090.05412.38
5.4.250.0090.05512.39
5.4.240.0070.03912.38
5.4.230.0060.03912.38
5.4.220.0100.03512.38
5.4.210.0080.03412.38
5.4.200.0090.04012.38
5.4.190.0090.04112.37
5.4.180.0050.04212.37
5.4.170.0070.05912.38
5.4.160.0120.04512.38
5.4.150.0050.03912.38
5.4.140.0110.04612.06
5.4.130.0120.04112.04
5.4.120.0050.03912.02
5.4.110.0080.04712.00
5.4.100.0080.03512.00
5.4.90.0070.03712.00
5.4.80.0080.03512.00
5.4.70.0060.03512.00
5.4.60.0080.03612.00
5.4.50.0090.03512.00
5.4.40.0060.03611.99
5.4.30.0100.03311.99
5.4.20.0070.04111.98
5.4.10.0090.04011.99
5.4.00.0030.04011.48
5.3.280.0080.05112.71
5.3.270.0090.05212.72
5.3.260.0090.05112.72
5.3.250.0050.03812.72
5.3.240.0040.04012.72
5.3.230.0080.03812.71
5.3.220.0080.03912.68
5.3.210.0050.04112.68
5.3.200.0120.05312.68
5.3.190.0080.03712.67
5.3.180.0070.04512.68
5.3.170.0050.03812.66
5.3.160.0100.03412.67
5.3.150.0090.05212.67
5.3.140.0070.04712.66
5.3.130.0080.03912.66
5.3.120.0080.04512.66
5.3.110.0050.04812.66
5.3.100.0090.04312.11
5.3.90.0120.03212.09
5.3.80.0080.03512.08
5.3.70.0080.04212.08
5.3.60.0080.03312.06
5.3.50.0070.03612.00
5.3.40.0050.03912.00
5.3.30.0060.03611.96
5.3.20.0040.03611.74
5.3.10.0060.03511.71
5.3.00.0090.04511.70

preferences:
134.69 ms | 1398 KiB | 7 Q