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); } } private function offsetSet($key, $value) { $this->throwEx(array('Do not directly set indices in a %s, use push() instead', __CLASS__)); return false; } 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)
8.3.60.0130.00718.56
8.3.50.0140.00721.98
8.3.40.0130.00318.71
8.3.30.0110.01118.97
8.3.20.0170.00020.34
8.3.10.0080.00021.92
8.3.00.0090.00622.25
8.2.180.0140.00716.88
8.2.170.0040.01122.96
8.2.160.0100.00320.52
8.2.150.0020.00524.18
8.2.140.0150.00024.66
8.2.130.0090.00026.16
8.2.120.0080.00019.23
8.2.110.0030.00620.47
8.2.100.0120.00019.46
8.2.90.0040.00419.18
8.2.80.0000.00817.97
8.2.70.0050.00317.50
8.2.60.0060.00317.92
8.2.50.0040.00418.07
8.2.40.0040.00418.09
8.2.30.0000.00818.02
8.2.20.0040.00417.68
8.2.10.0000.00817.52
8.2.00.0030.00517.64
8.1.280.0030.01425.92
8.1.270.0110.00722.14
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0060.00323.83
8.1.230.0120.00019.15
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0030.00717.35
8.1.190.0040.00417.54
8.1.180.0000.00918.10
8.1.170.0030.00518.41
8.1.160.0040.00422.06
8.1.150.0040.00418.61
8.1.140.0000.00717.41
8.1.130.0000.00717.80
8.1.120.0000.00717.39
8.1.110.0000.00717.32
8.1.100.0050.00317.32
8.1.90.0040.00417.29
8.1.80.0020.00517.39
8.1.70.0040.00417.41
8.1.60.0000.00817.51
8.1.50.0000.00817.38
8.1.40.0030.00617.51
8.1.30.0020.00517.61
8.1.20.0030.00517.50
8.1.10.0050.00517.39
8.1.00.0060.00317.32
8.0.300.0040.00418.77
8.0.290.0040.00417.18
8.0.280.0050.00218.41
8.0.270.0070.00017.16
8.0.260.0000.00716.85
8.0.250.0030.00317.01
8.0.240.0040.00416.93
8.0.230.0030.00317.02
8.0.220.0030.00316.96
8.0.210.0070.00016.94
8.0.200.0030.00616.81
8.0.190.0040.00416.87
8.0.180.0040.00416.91
8.0.170.0000.00816.94
8.0.160.0050.00216.81
8.0.150.0000.00716.79
8.0.140.0030.00516.77
8.0.130.0040.00413.38
8.0.120.0040.00416.88
8.0.110.0000.00716.87
8.0.100.0040.00417.00
8.0.90.0000.00816.98
8.0.80.0080.01216.96
8.0.70.0080.00016.88
8.0.60.0000.00716.79
8.0.50.0000.00716.87
8.0.30.0080.01116.88
8.0.20.0050.01717.40
8.0.10.0030.00516.99
8.0.00.0110.00916.65
7.4.330.0050.00015.08
7.4.320.0030.00316.57
7.4.300.0000.00716.46
7.4.290.0070.00016.52
7.4.280.0000.00816.37
7.4.270.0000.00716.61
7.4.260.0020.00516.31
7.4.250.0000.00716.42
7.4.240.0060.00216.43
7.4.230.0000.00716.21
7.4.220.0120.01216.39
7.4.210.0080.00716.52
7.4.200.0000.00816.54
7.4.190.0030.00316.65
7.4.160.0080.01316.46
7.4.150.0120.00617.40
7.4.140.0080.01017.86
7.4.130.0110.00716.40
7.4.120.0080.01116.54
7.4.110.0080.01116.43
7.4.100.0130.00316.55
7.4.90.0130.00916.54
7.4.80.0100.01319.39
7.4.70.0040.01216.53
7.4.60.0060.01216.26
7.4.50.0000.00816.54
7.4.40.0100.00322.77
7.4.30.0080.00816.53
7.4.00.0000.01314.88
7.3.330.0000.00613.23
7.3.320.0060.00013.08
7.3.310.0040.00416.20
7.3.300.0030.00316.27
7.3.290.0070.01016.40
7.3.280.0110.00616.28
7.3.270.0030.01617.40
7.3.260.0050.01416.42
7.3.250.0110.00616.41
7.3.240.0130.00316.31
7.3.230.0080.00916.57
7.3.210.0120.00416.23
7.3.200.0030.01319.39
7.3.190.0100.01016.46
7.3.180.0080.00816.38
7.3.170.0110.00516.56
7.3.160.0120.00416.39
7.3.120.0030.00614.80
7.2.330.0100.00716.55
7.2.320.0130.01316.45
7.2.310.0200.00316.49
7.2.300.0000.01916.54
7.2.290.0070.01016.56
7.2.60.0070.00716.61
7.2.50.0080.00316.79
7.1.200.0070.00715.47
7.1.70.0000.00717.10
7.1.60.0060.00919.82
7.1.50.0070.01716.86
7.1.00.0070.06722.32
7.0.200.0100.00716.51
7.0.140.0030.07022.07
7.0.60.0030.04019.96
7.0.50.0070.07317.88
7.0.40.0030.04320.23
7.0.30.0270.08320.24
7.0.20.0170.04320.09
7.0.10.0100.06720.07
7.0.00.0070.07020.07
5.6.280.0070.06720.91
5.6.210.0070.07320.77
5.6.200.0100.06018.24
5.6.190.0070.06020.42
5.6.180.3300.04720.33
5.6.170.0300.06720.45
5.6.160.0100.08020.57
5.6.150.0000.08318.33
5.6.140.0030.06018.24
5.6.130.0070.07318.18
5.6.120.0030.04021.02
5.6.110.0130.09021.10
5.6.100.0130.08021.04
5.6.90.0070.03721.14
5.6.80.0130.07320.52
5.6.70.4470.04320.41
5.5.350.0000.08720.45
5.5.340.0130.07017.99
5.5.330.0030.08320.27
5.5.320.3470.05020.24
5.5.310.0230.03320.33
5.5.300.0130.04017.94
5.5.290.0100.08017.97
5.5.280.0130.08020.91
5.5.270.0170.05020.89
5.5.260.0100.08020.67
5.5.250.0100.07720.61
5.5.240.0330.06320.27
5.4.450.0270.06019.31
5.4.440.0930.06319.57
5.4.430.0800.06019.27
5.4.420.0530.06019.59
5.4.410.0730.05019.30
5.4.400.1100.06318.80
5.4.390.0970.05719.05
5.4.380.0300.05718.80
5.4.370.0170.05318.61
5.4.360.0270.04318.57
5.4.350.0330.03718.80
5.4.340.0100.06018.74
5.4.320.0050.03812.52
5.4.310.0070.03712.51
5.4.300.0050.04312.52
5.4.290.0110.03812.51
5.4.280.0060.03712.38
5.4.270.0070.03712.38
5.4.260.0090.03612.38
5.4.250.0100.04712.38
5.4.240.0090.04712.38
5.4.230.0070.03812.38
5.4.220.0040.04812.38
5.4.210.0070.03612.37
5.4.200.0120.04112.38
5.4.190.0100.04012.37
5.4.180.0110.03312.37
5.4.170.0070.03712.38
5.4.160.0060.04012.38
5.4.150.0080.04312.37
5.4.140.0080.03812.06
5.4.130.0070.03712.04
5.4.120.0110.03412.00
5.4.110.0070.03712.00
5.4.100.0080.03512.00
5.4.90.0050.04012.00
5.4.80.0110.03312.00
5.4.70.0040.03812.00
5.4.60.0120.03912.00
5.4.50.0060.04911.99
5.4.40.0110.04111.98
5.4.30.0130.04411.98
5.4.20.0130.04611.98
5.4.10.0080.03911.98
5.4.00.0100.04811.47
5.3.290.0050.04412.80
5.3.280.0100.04312.71
5.3.270.0100.03912.72
5.3.260.0060.04112.72
5.3.250.0060.03812.72
5.3.240.0060.03812.72
5.3.230.0070.03912.71
5.3.220.0060.03912.68
5.3.210.0150.04712.68
5.3.200.0070.05412.68
5.3.190.0140.05212.68
5.3.180.0140.05212.67
5.3.170.0120.05212.67
5.3.160.0140.05112.68
5.3.150.0100.05312.68
5.3.140.0090.03812.66
5.3.130.0080.04212.66
5.3.120.0110.06012.65
5.3.110.0080.05412.66
5.3.100.0110.04712.12
5.3.90.0070.04012.10
5.3.80.0090.04912.09
5.3.70.0070.03812.09
5.3.60.0080.04512.07
5.3.50.0100.04012.02
5.3.40.0080.05112.02
5.3.30.0120.04611.98
5.3.20.0090.04711.76
5.3.10.0110.03211.73
5.3.00.0040.03911.72
5.2.170.0110.0399.22
5.2.160.0070.0369.22
5.2.150.0040.0349.21
5.2.140.0050.0349.21
5.2.130.0080.0319.17
5.2.120.0040.0309.18
5.2.110.0090.0319.18
5.2.100.0080.0379.18
5.2.90.0110.0289.17
5.2.80.0030.0359.18
5.2.70.0070.0299.17
5.2.60.0060.0379.13
5.2.50.0050.0349.09
5.2.40.0080.0279.07
5.2.30.0080.0359.05
5.2.20.0120.0359.04
5.2.10.0060.0328.95
5.2.00.0060.0368.81
5.1.60.0060.0368.10
5.1.50.0040.0288.10
5.1.40.0100.0378.08
5.1.30.0080.0398.42
5.1.20.0100.0308.46
5.1.10.0110.0318.18
5.1.00.0060.0298.18
5.0.50.0030.0226.65
5.0.40.0060.0186.52
5.0.30.0020.0336.33
5.0.20.0060.0176.32
5.0.10.0030.0226.30
5.0.00.0020.0326.28
4.4.90.0030.0154.78
4.4.80.0020.0234.75
4.4.70.0060.0204.76
4.4.60.0040.0224.75
4.4.50.0040.0214.77
4.4.40.0050.0294.71
4.4.30.0050.0134.76
4.4.20.0020.0174.85
4.4.10.0050.0144.85
4.4.00.0030.0264.76
4.3.110.0040.0154.67
4.3.100.0020.0164.66
4.3.90.0020.0154.63
4.3.80.0010.0274.58
4.3.70.0040.0144.63
4.3.60.0040.0144.63
4.3.50.0030.0164.63
4.3.40.0010.0314.54
4.3.30.0030.0203.28
4.3.20.0010.0173.27
4.3.10.0040.0143.23
4.3.00.0030.0238.13

preferences:
44.68 ms | 400 KiB | 5 Q