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 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.0040.01218.41
8.3.50.0090.01221.98
8.3.40.0040.01419.01
8.3.30.0120.00319.04
8.3.20.0080.00020.18
8.3.10.0080.00022.00
8.3.00.0080.00022.39
8.2.180.0160.00616.88
8.2.170.0070.00722.96
8.2.160.0120.00320.46
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0160.00326.16
8.2.120.0080.00019.36
8.2.110.0100.00021.18
8.2.100.0080.00418.03
8.2.90.0060.00319.34
8.2.80.0040.00417.97
8.2.70.0030.00717.75
8.2.60.0030.00518.05
8.2.50.0060.00318.07
8.2.40.0000.00818.22
8.2.30.0000.00718.18
8.2.20.0000.00817.80
8.2.10.0030.00619.50
8.2.00.0060.00317.87
8.1.280.0150.00025.92
8.1.270.0030.01322.04
8.1.260.0000.00826.35
8.1.250.0050.00328.09
8.1.240.0160.00621.31
8.1.230.0060.00617.42
8.1.220.0000.00817.79
8.1.210.0050.00318.77
8.1.200.0030.00617.35
8.1.190.0080.00017.35
8.1.180.0000.00818.10
8.1.170.0000.00818.71
8.1.160.0070.00022.03
8.1.150.0000.00818.59
8.1.140.0030.00517.47
8.1.130.0000.00717.77
8.1.120.0040.00417.55
8.1.110.0040.00417.49
8.1.100.0040.00417.52
8.1.90.0020.00517.38
8.1.80.0000.00717.50
8.1.70.0050.00217.45
8.1.60.0110.00017.63
8.1.50.0040.00417.55
8.1.40.0000.00817.57
8.1.30.0000.00817.64
8.1.20.0080.00017.52
8.1.10.0080.00017.60
8.1.00.0070.00017.58
8.0.300.0070.00018.77
8.0.290.0080.00016.75
8.0.280.0000.00718.47
8.0.270.0000.00717.33
8.0.260.0000.00716.91
8.0.250.0030.00316.94
8.0.240.0040.00416.96
8.0.230.0040.00417.06
8.0.220.0000.00716.89
8.0.210.0070.00016.86
8.0.200.0070.00017.07
8.0.190.0030.00616.95
8.0.180.0000.00717.02
8.0.170.0000.00816.91
8.0.160.0040.00417.02
8.0.150.0040.00416.87
8.0.140.0040.00416.99
8.0.130.0030.00313.39
8.0.120.0030.00516.95
8.0.110.0040.00416.80
8.0.100.0000.00716.80
8.0.90.0050.00216.82
8.0.80.0030.01317.04
8.0.70.0040.00416.78
8.0.60.0000.00717.09
8.0.50.0050.00216.88
8.0.30.0110.01017.16
8.0.20.0080.01317.40
8.0.10.0000.00717.14
8.0.00.0060.01116.80
7.4.330.0000.00515.00
7.4.320.0030.00316.54
7.4.300.0030.00316.53
7.4.290.0040.00416.55
7.4.280.0030.00316.54
7.4.270.0030.00316.56
7.4.260.0040.00716.49
7.4.250.0080.00016.57
7.4.240.0020.00516.58
7.4.230.0030.00316.61
7.4.220.0070.01116.68
7.4.210.0030.01216.57
7.4.200.0040.00416.70
7.4.190.0070.00016.66
7.4.160.0050.01216.70
7.4.150.0140.00917.40
7.4.140.0110.00817.86
7.4.130.0150.00816.49
7.4.120.0110.00716.61
7.4.110.0030.01416.52
7.4.100.0160.00616.66
7.4.90.0110.00716.59
7.4.80.0100.00819.39
7.4.70.0030.01416.46
7.4.60.0070.01016.65
7.4.50.0000.00516.46
7.4.40.0090.00622.77
7.4.30.0160.00616.63
7.4.10.0140.00315.22
7.4.00.0090.00814.98
7.3.330.0040.00213.39
7.3.320.0000.00613.38
7.3.310.0000.00716.36
7.3.300.0000.00716.46
7.3.290.0050.01016.52
7.3.280.0090.00816.47
7.3.270.0040.01217.40
7.3.260.0160.00916.38
7.3.250.0120.00516.40
7.3.240.0040.01316.39
7.3.230.0100.01316.41
7.3.210.0120.00616.67
7.3.200.0150.00319.39
7.3.190.0130.00916.32
7.3.180.0110.00716.73
7.3.170.0000.01616.69
7.3.160.0080.01416.58
7.3.130.0090.00914.82
7.3.120.0070.01114.99
7.3.110.0030.01414.98
7.3.100.0120.00014.96
7.3.90.0090.00614.97
7.3.80.0090.00914.97
7.3.70.0030.01214.70
7.3.60.0000.01614.95
7.3.50.0090.00314.60
7.3.40.0110.00314.92
7.3.30.0060.00914.83
7.3.20.0060.00616.82
7.3.10.0040.01116.61
7.3.00.0070.00716.75
7.2.330.0090.01916.53
7.2.320.0070.01616.73
7.2.310.0120.00416.71
7.2.300.0100.01016.64
7.2.290.0070.01716.82
7.2.260.0070.01015.22
7.2.250.0100.00715.09
7.2.240.0040.01114.92
7.2.230.0060.01015.16
7.2.220.0070.01414.98
7.2.210.0060.00315.29
7.2.200.0040.01115.25
7.2.190.0030.00915.13
7.2.180.0000.01615.16
7.2.170.0080.00815.18
7.2.160.0070.00715.23
7.2.150.0040.00716.66
7.2.140.0030.01017.03
7.2.130.0040.00816.92
7.2.120.0070.00317.11
7.2.110.0000.01017.01
7.2.100.0110.00417.01
7.2.90.0040.00716.85
7.2.80.0030.01516.98
7.2.70.0080.00817.09
7.2.60.0020.01116.80
7.2.50.0050.00517.04
7.2.40.0100.00316.85
7.2.30.0000.01116.85
7.2.20.0150.00317.13
7.2.10.0090.00317.08
7.2.00.0090.00518.10
7.1.330.0070.00715.77
7.1.320.0090.00915.77
7.1.310.0060.00615.89
7.1.300.0030.00715.57
7.1.290.0070.01115.80
7.1.280.0030.01015.57
7.1.270.0090.00015.80
7.1.260.0050.00515.63
7.1.250.0000.01315.52
7.1.240.0000.01115.91
7.1.230.0030.01015.92
7.1.220.0060.00615.68
7.1.210.0090.00615.82
7.1.200.0050.00715.82
7.1.190.0030.00715.75
7.1.180.0030.00615.93
7.1.170.0090.00615.68
7.1.160.0030.00615.88
7.1.150.0040.00815.86
7.1.140.0040.01415.80
7.1.130.0040.00715.77
7.1.120.0070.01015.94
7.1.110.0070.00715.98
7.1.100.0060.00617.02
7.1.90.0030.00715.80
7.1.80.0000.01015.94
7.1.70.0010.00816.31
7.1.60.0050.01117.93
7.1.50.0040.01216.51
7.1.40.0060.00615.92
7.1.30.0030.01415.75
7.1.20.0000.01415.69
7.1.10.0090.00615.85
7.1.00.0030.04319.14
7.0.330.0050.00515.18
7.0.320.0040.01115.48
7.0.310.0000.01315.19
7.0.300.0030.01015.42
7.0.290.0080.00415.52
7.0.280.0100.00315.61
7.0.270.0030.01015.39
7.0.260.0040.01115.50
7.0.250.0030.00615.59
7.0.240.0060.00315.52
7.0.230.0060.00315.33
7.0.220.0040.00815.36
7.0.210.0000.01015.56
7.0.200.0070.00816.15
7.0.190.0090.00415.46
7.0.180.0070.00415.30
7.0.170.0030.00615.46
7.0.160.0030.00715.50
7.0.150.0000.00915.48
7.0.140.0030.04218.64
7.0.130.0000.00815.62
7.0.120.0040.01215.40
7.0.110.0060.00615.57
7.0.100.0030.00915.48
7.0.90.0000.01215.50
7.0.80.0000.01015.62
7.0.70.0060.00615.66
7.0.60.0130.03317.75
7.0.50.0070.04816.73
7.0.40.0060.02616.81
7.0.30.0300.03316.80
7.0.20.0130.03616.72
7.0.10.0070.02416.85
7.0.00.0070.04616.93
5.6.400.0080.00414.68
5.6.390.0080.00414.44
5.6.380.0100.00714.58
5.6.370.0080.00814.52
5.6.360.0040.01114.23
5.6.350.0000.00914.29
5.6.340.0060.00814.77
5.6.330.0090.00614.55
5.6.320.0130.00314.31
5.6.310.0090.00314.36
5.6.300.0060.00714.49
5.6.290.0030.00914.51
5.6.280.0110.03017.90
5.6.270.0000.01714.41
5.6.260.0040.00814.66
5.6.250.0060.00314.86
5.6.240.0130.00314.63
5.6.230.0030.00914.47
5.6.220.0070.00814.77
5.6.210.0070.04817.62
5.6.200.0070.03816.22
5.6.190.0050.02417.41
5.6.180.0200.02717.48
5.6.170.0200.04417.62
5.6.160.0050.04017.36
5.6.150.0060.03516.50
5.6.140.0090.04016.28
5.6.130.0080.04316.41
5.6.120.0060.03617.72
5.6.110.0050.02617.79
5.6.100.0080.04317.74
5.6.90.0090.02717.85
5.6.80.0050.04017.42
5.6.70.2280.02017.55
5.6.60.0040.01114.14
5.6.50.0030.00714.19
5.6.40.0060.00614.41
5.6.30.0080.00314.26
5.6.20.0110.00414.46
5.6.10.0030.00914.38
5.6.00.0060.00314.39
5.5.380.0070.00714.41
5.5.370.0060.01114.68
5.5.360.0080.00314.88
5.5.350.0050.04617.29
5.5.340.0110.02116.13
5.5.330.0020.04717.55
5.5.320.0120.02517.37
5.5.310.0190.03417.37
5.5.300.0100.04216.34
5.5.290.0080.04216.31
5.5.280.0080.03617.64
5.5.270.0070.05017.55
5.5.260.0070.04717.68
5.5.250.0120.03617.65
5.5.240.0070.01917.38
5.5.230.0000.01214.55
5.5.220.0060.00614.53
5.5.210.0100.00714.54
5.5.200.0090.00614.73
5.5.190.0060.00314.25
5.5.180.0070.00714.57
5.5.170.0030.01214.44
5.5.160.0060.00314.37
5.5.150.0040.00714.60
5.5.140.0060.00914.50
5.5.130.0040.01414.57
5.5.120.0070.00714.29
5.5.110.0070.01014.26
5.5.100.0120.00014.56
5.5.90.0090.00414.50
5.5.80.0000.01014.31
5.5.70.0040.00814.49
5.5.60.0060.00914.54
5.5.50.0070.01014.16
5.5.40.0080.00814.39
5.5.30.0000.01114.21
5.5.20.0070.00714.60
5.5.10.0030.00814.50
5.5.00.0080.00414.39
5.4.450.0180.02715.27
5.4.440.0080.03415.27
5.4.430.0070.03315.25
5.4.420.0100.03215.39
5.4.410.0070.04715.37
5.4.400.0430.00415.12
5.4.390.0420.00115.03
5.4.380.0180.03014.83
5.4.370.0130.03314.96
5.4.360.0160.02515.00
5.4.350.0110.02814.81
5.4.340.0100.03014.91
5.4.330.0090.00611.44
5.4.320.0020.02411.97
5.4.310.0080.02611.94
5.4.300.0060.02011.85
5.4.290.0020.02611.79
5.4.280.0050.02711.92
5.4.270.0090.01911.86
5.4.260.0020.02611.86
5.4.250.0060.02311.80
5.4.240.0040.02311.94
5.4.230.0060.02411.72
5.4.220.0020.02311.81
5.4.210.0060.02911.74
5.4.200.0060.02811.75
5.4.190.0050.02611.72
5.4.180.0080.02211.84
5.4.170.0080.01911.81
5.4.160.0090.02311.78
5.4.150.0020.02611.84
5.4.140.0040.02411.56
5.4.130.0060.02311.59
5.4.120.0040.02311.55
5.4.110.0050.02411.54
5.4.100.0050.02211.54
5.4.90.0080.01911.60
5.4.80.0020.02711.61
5.4.70.0080.02211.69
5.4.60.0060.02111.53
5.4.50.0060.02511.54
5.4.40.0070.02811.60
5.4.30.0060.02811.63
5.4.20.0060.02811.62
5.4.10.0060.02211.64
5.4.00.0060.02511.33
5.3.290.0060.02411.94
5.3.280.0050.02211.89
5.3.270.0050.02111.90
5.3.260.0070.02711.89
5.3.250.0050.02811.89
5.3.240.0020.02611.89
5.3.230.0080.02011.89
5.3.220.0080.02111.87
5.3.210.0070.02311.87
5.3.200.0040.02111.87
5.3.190.0040.02411.87
5.3.180.0070.02311.87
5.3.170.0050.02511.87
5.3.160.0070.02811.87
5.3.150.0090.02911.87
5.3.140.0110.03211.86
5.3.130.0070.02111.86
5.3.120.0060.02811.86
5.3.110.0060.02311.86
5.3.100.0070.02411.60
5.3.90.0040.02111.59
5.3.80.0080.01911.58
5.3.70.0060.02111.58
5.3.60.0110.02311.58
5.3.50.0080.02211.55
5.3.40.0070.02711.55
5.3.30.0060.02111.53
5.3.20.0050.02011.42
5.3.10.0040.02011.40
5.3.00.0030.02311.40
5.2.170.0070.0329.23
5.2.160.0060.0429.23
5.2.150.0110.0519.23
5.2.140.0140.0619.22
5.2.130.0080.0479.18
5.2.120.0050.0479.18
5.2.110.0080.0389.20
5.2.100.0090.0429.19
5.2.90.0100.0419.18
5.2.80.0140.0649.19
5.2.70.0180.0859.18
5.2.60.0070.0339.14
5.2.50.0070.0299.11
5.2.40.0110.0279.09
5.2.30.0050.0319.07
5.2.20.0050.0359.05
5.2.10.0060.0288.95
5.2.00.0090.0378.82
5.1.60.0080.0328.12
5.1.50.0070.0338.12
5.1.40.0090.0298.10
5.1.30.0070.0288.44
5.1.20.0060.0408.47
5.1.10.0070.0248.19
5.1.00.0090.0228.19
5.0.50.0050.0206.67
5.0.40.0060.0236.53
5.0.30.0060.0426.34
5.0.20.0040.0246.33
5.0.10.0060.0276.31
5.0.00.0060.0446.30
4.4.90.0080.0194.78
4.4.80.0050.0214.75
4.4.70.0050.0204.75
4.4.60.0050.0154.75
4.4.50.0060.0214.77
4.4.40.0020.0334.70
4.4.30.0040.0204.76
4.4.20.0040.0164.85
4.4.10.0020.0184.85
4.4.00.0020.0274.75
4.3.110.0040.0154.67
4.3.100.0040.0154.67
4.3.90.0030.0164.63
4.3.80.0040.0244.59
4.3.70.0050.0134.63
4.3.60.0070.0114.63
4.3.50.0060.0164.63
4.3.40.0050.0254.53
4.3.30.0030.0163.28
4.3.20.0040.0233.26
4.3.10.0020.0173.23
4.3.00.0000.0235.97

preferences:
47.54 ms | 401 KiB | 5 Q