3v4l.org

run code in 300+ PHP versions simultaneously
<?PHP class InvalidStateException extends RuntimeException { } class Compiler { private $ptr; private $arr; private $code; private $commands = array('>', '<', '+', '-', '.', ',', '[', ']'); private $call_stack = array(); private $cellsize = 8; public function parseString($code, $throwException = true) { $this->code = $code; for ($i=0;$i<strlen($this->code);$i++) { $c = substr($this->code, $i, 1); if (!in_array($c, $this->commands)) { continue; } } } public function execute($code) { $this->arr = array(0 => 0); $this->ptr = 0; $this->code = $code; for ($this->i=0;$this->i<strlen($this->code);$this->i++) { $c = $this->c = substr($this->code, $this->i, 1); if (!in_array($c, $this->commands)) { continue; } elseif ($c == '>') { $this->increment_pointer(); } elseif ($c == '<') { $this->decrement_pointer(); } elseif ($c == '+') { $this->increment_val(); } elseif ($c == '-') { $this->decrement_val(); } elseif ($c == '.') { $this->output_val(); } elseif ($c == ',') { $this->store_val($this->input_val()); } elseif ($c == '[') { $this->loop($this->i); } } } private function stack($func=null) { if (is_null($func)) { if (count($this->call_stack) == 0) { throw new InvalidStateException("Trying to pop empty call stack."); return false; } array_pop($this->call_stack); return true; } else { $info = array('command' => $this->c, 'pos' => $this->i, 'internal_function' => $func); array_push($this->call_stack, $info); return true; } } public function minimum_cellsize() { return (-1*(pow(2, $this->cellsize-1))); } public function maximum_cellsize() { return pow(2, $this->cellsize-1)-1; } private function increment_pointer() { $this->stack(__FUNCTION__); $this->ptr++; if (!isset($this->arr[$this->ptr])) $this->arr[$this->ptr] = 0; $this->stack(); return true; } private function decrement_pointer() { $this->stack(__FUNCTION__); $this->ptr--; if ($this->ptr < 0) { throw new InvalidStateException("The data pointer is less than 0."); return false; } $this->stack(); return true; } private function increment_val() { $x = $this->arr[$this->ptr]++; if ($x < $this->minimum_cellsize()) { $this->arr[$this->ptr] = $this->maximum_cellsize(); } elseif ($x > $this->maximum_cellsize()) { $this->arr[$this->ptr] = $this->minimum_cellsize(); } return true; } private function output_val() { $c = $this->arr[$this->ptr]; echo chr($c); } private function store_val($chr) { $x = ord($chr); $this->arr[$this->ptr] = $x; } private function input_val() { return fgets(STDIN); } public function getCallStack() { return $this->call_stack; } } $c = new Compiler(); $bf = '+++++++++ +++++++++ +++++++++ + > +++++++++ +++++++++ +++++++++ ++ < . < .'; try { $c->execute($bf); } catch (Exception $e) { var_dump($c->getCallStack()); } ?>

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.0090.00918.55
8.3.50.0120.00521.14
8.3.40.0120.00318.96
8.3.30.0070.00720.34
8.3.20.0040.00420.16
8.3.10.0030.00521.95
8.3.00.0000.00820.64
8.2.180.0160.00317.00
8.2.170.0110.00322.96
8.2.160.0030.01020.47
8.2.150.0040.00424.18
8.2.140.0070.01324.66
8.2.130.0080.00026.16
8.2.120.0050.00319.66
8.2.110.0060.00322.02
8.2.100.0090.00317.97
8.2.90.0000.00819.11
8.2.80.0040.00419.39
8.2.70.0030.00617.63
8.2.60.0000.00818.05
8.2.50.0050.00318.07
8.2.40.0040.00418.16
8.2.30.0070.00418.16
8.2.20.0000.00717.73
8.2.10.0050.00317.95
8.2.00.0030.00617.88
8.1.280.0140.00725.92
8.1.270.0080.00024.66
8.1.260.0000.00926.35
8.1.250.0080.00028.09
8.1.240.0030.00623.96
8.1.230.0040.00819.01
8.1.220.0000.00817.80
8.1.210.0000.00818.77
8.1.200.0060.00317.47
8.1.190.0000.00917.66
8.1.180.0090.00019.01
8.1.170.0050.00518.68
8.1.160.0030.00622.19
8.1.150.0070.00018.59
8.1.140.0060.00317.56
8.1.130.0000.00717.82
8.1.120.0040.00417.52
8.1.110.0040.00417.51
8.1.100.0050.00317.55
8.1.90.0050.00217.57
8.1.80.0040.00417.55
8.1.70.0070.00017.54
8.1.60.0000.00817.54
8.1.50.0080.00017.48
8.1.40.0050.00317.63
8.1.30.0000.00817.73
8.1.20.0040.00417.67
8.1.10.0090.00017.64
8.1.00.0080.00417.55
8.0.300.0000.00818.77
8.0.290.0070.00017.30
8.0.280.0070.00018.39
8.0.270.0030.00317.32
8.0.260.0030.00316.83
8.0.250.0030.00317.05
8.0.240.0030.00617.03
8.0.230.0030.00317.11
8.0.220.0000.00817.02
8.0.210.0030.00316.94
8.0.200.0030.00317.11
8.0.190.0040.00416.96
8.0.180.0000.00816.91
8.0.170.0000.00916.94
8.0.160.0040.00417.04
8.0.150.0020.00516.91
8.0.140.0040.00417.02
8.0.130.0030.00313.41
8.0.120.0050.00316.86
8.0.110.0050.00217.05
8.0.100.0050.00317.09
8.0.90.0040.00417.00
8.0.80.0030.01317.07
8.0.70.0000.00817.06
8.0.60.0040.00416.92
8.0.50.0040.00417.02
8.0.30.0130.00617.27
8.0.20.0110.01017.40
8.0.10.0070.00017.11
8.0.00.0090.01116.98
7.4.330.0050.00015.00
7.4.320.0000.00816.70
7.4.300.0000.00716.63
7.4.290.0030.00316.70
7.4.280.0030.00316.56
7.4.270.0060.00016.63
7.4.260.0000.01016.58
7.4.250.0050.00316.56
7.4.240.0000.00716.69
7.4.230.0070.00016.68
7.4.220.0100.01016.68
7.4.210.0060.01116.62
7.4.200.0050.00216.60
7.4.190.0030.00316.63
7.4.160.0060.01216.56
7.4.150.0090.00917.40
7.4.140.0120.00917.86
7.4.130.0070.01216.71
7.4.120.0100.00716.76
7.4.110.0040.01416.85
7.4.100.0080.00816.76
7.4.90.0030.01416.54
7.4.80.0080.00819.39
7.4.70.0100.00716.51
7.4.60.0100.00716.58
7.4.50.0000.00816.61
7.4.40.0030.01022.77
7.4.30.0080.01216.58
7.4.10.0030.01315.07
7.4.00.0140.00315.23
7.3.330.0000.00613.34
7.3.320.0050.00013.50
7.3.310.0070.00016.37
7.3.300.0040.00416.46
7.3.290.0060.00916.50
7.3.280.0090.00916.50
7.3.270.0080.01717.40
7.3.260.0230.02916.53
7.3.250.0110.00616.51
7.3.240.0060.01216.57
7.3.230.0120.00616.59
7.3.210.0080.00816.59
7.3.200.0060.01619.39
7.3.190.0070.01016.74
7.3.180.0030.01316.77
7.3.170.0090.00816.51
7.3.160.0100.00616.47
7.3.130.0120.00614.96
7.3.120.0050.01214.96
7.3.110.0060.00914.69
7.3.100.0000.01214.92
7.3.90.0030.01415.08
7.3.80.0030.00715.28
7.3.70.0070.00714.85
7.3.60.0060.01014.95
7.3.50.0040.01514.83
7.3.40.0100.00014.93
7.3.30.0070.01014.74
7.3.20.0100.00316.53
7.3.10.0070.00416.55
7.3.00.0030.00716.67
7.2.330.0110.00716.86
7.2.320.0140.00416.72
7.2.310.0140.00416.63
7.2.300.0100.00716.91
7.2.290.0090.00916.62
7.2.260.0070.01115.10
7.2.250.0090.00415.25
7.2.240.0030.01315.06
7.2.230.0030.01215.09
7.2.220.0140.00715.41
7.2.210.0060.00315.18
7.2.200.0070.00714.94
7.2.190.0000.01915.13
7.2.180.0040.01115.17
7.2.170.0070.00715.18
7.2.160.0120.00315.27
7.2.150.0130.00317.17
7.2.140.0070.00316.91
7.2.130.0060.01116.89
7.2.120.0030.00716.93
7.2.110.0100.00016.66
7.2.100.0070.01016.75
7.2.90.0060.00616.98
7.2.80.0110.00316.98
7.2.70.0040.01416.71
7.2.60.0120.00317.07
7.2.50.0120.00317.03
7.2.40.0000.01516.77
7.2.30.0030.00716.87
7.2.20.0100.00317.14
7.2.10.0060.00917.20
7.2.00.0040.01218.06
7.1.330.0030.01315.71
7.1.320.0090.00915.97
7.1.310.0090.00315.68
7.1.300.0030.01515.85
7.1.290.0070.01015.79
7.1.280.0030.01315.96
7.1.270.0030.00915.86
7.1.260.0000.01315.86
7.1.250.0100.00615.91
7.1.240.0030.01015.86
7.1.230.0060.00315.69
7.1.220.0110.00415.80
7.1.210.0000.01315.98
7.1.200.0070.00715.97
7.1.190.0100.00715.67
7.1.180.0090.00615.82
7.1.170.0030.01015.98
7.1.160.0040.00815.74
7.1.150.0060.00315.71
7.1.140.0000.01216.05
7.1.130.0030.00915.89
7.1.120.0100.00615.91
7.1.110.0070.01115.73
7.1.100.0070.00916.84
7.1.90.0110.00415.88
7.1.80.0030.01015.94
7.1.70.0040.00916.57
7.1.60.0050.01517.32
7.1.50.0090.00516.38
7.1.40.0030.00615.60
7.1.30.0030.01015.84
7.1.20.0070.00715.79
7.1.10.0060.00915.77
7.1.00.0030.02218.97
7.0.330.0000.01215.38
7.0.320.0060.00915.46
7.0.310.0100.00315.36
7.0.300.0060.00315.26
7.0.290.0000.01715.41
7.0.280.0080.00015.33
7.0.270.0050.00515.49
7.0.260.0070.01115.44
7.0.250.0060.01015.57
7.0.240.0070.00715.56
7.0.230.0000.01215.55
7.0.220.0090.00615.50
7.0.210.0030.01315.54
7.0.200.0120.00515.26
7.0.190.0100.00315.59
7.0.180.0070.00715.53
7.0.170.0100.00315.63
7.0.160.0040.00915.45
7.0.150.0060.00915.65
7.0.140.0020.04218.81
7.0.130.0090.00915.41
7.0.120.0030.01015.48
7.0.110.0060.00615.38
7.0.100.0080.02317.70
7.0.90.0030.02817.61
7.0.80.0050.02817.65
7.0.70.0030.04617.61
7.0.60.0170.02617.71
7.0.50.0100.03417.89
7.0.40.0050.04616.85
7.0.30.0070.05016.89
7.0.20.0050.02316.77
7.0.10.0020.03116.77
7.0.00.0020.04616.69
5.6.400.0070.01014.64
5.6.390.0110.00414.52
5.6.380.0150.00314.63
5.6.370.0000.01114.63
5.6.360.0030.00914.53
5.6.350.0090.00314.64
5.6.340.0040.01214.24
5.6.330.0030.01014.70
5.6.320.0090.01214.63
5.6.310.0070.01114.69
5.6.300.0060.00314.53
5.6.290.0030.00714.80
5.6.280.0040.04217.80
5.6.270.0000.01214.88
5.6.260.0040.00714.48
5.6.250.0080.02217.59
5.6.240.0030.04417.60
5.6.230.0120.03817.65
5.6.220.0070.04217.60
5.6.210.0080.04017.48
5.6.200.0080.02517.72
5.6.190.0080.03317.78
5.6.180.0070.04417.78
5.6.170.0100.04517.81
5.6.160.0080.04317.70
5.6.150.0050.04117.98
5.6.140.0060.04417.66
5.6.130.0130.03717.71
5.6.120.0100.03917.78
5.6.110.0090.04417.83
5.6.100.0070.02517.88
5.6.90.0070.04317.75
5.6.80.0050.02717.32
5.6.70.0080.04417.56
5.6.60.0040.03217.48
5.6.50.0070.03917.54
5.6.40.0120.02317.46
5.6.30.0140.02317.54
5.6.20.0070.04417.36
5.6.10.0080.04317.53
5.6.00.0020.04817.53
5.5.380.0070.03317.49
5.5.370.0050.02517.55
5.5.360.0100.03717.60
5.5.350.0030.04517.62
5.5.340.0080.03717.71
5.5.330.0080.04217.66
5.5.320.0140.03917.73
5.5.310.0050.02517.78
5.5.300.0090.04217.72
5.5.290.0040.03917.62
5.5.280.0070.05017.50
5.5.270.0050.04317.66
5.5.260.0090.04117.56
5.5.250.0070.04417.65
5.5.240.0100.03717.25
5.5.230.0080.04217.45
5.5.220.0040.03017.39
5.5.210.0060.02717.38
5.5.200.0050.04617.21
5.5.190.0090.02217.31
5.5.180.0100.02917.25
5.5.170.0070.00314.56
5.5.160.0080.02317.42
5.5.150.0110.04117.44
5.5.140.0130.03317.27
5.5.130.0050.04817.32
5.5.120.0030.03517.27
5.5.110.0090.02117.42
5.5.100.0100.03817.13
5.5.90.0070.04417.29
5.5.80.0050.04317.20
5.5.70.0020.02817.23
5.5.60.0020.03217.35
5.5.50.0070.04217.25
5.5.40.0070.03317.27
5.5.30.0070.04617.10
5.5.20.0030.02817.32
5.5.10.0090.03817.13
5.5.00.0050.02717.11
5.4.450.0020.04816.19
5.4.440.0050.04216.17
5.4.430.0100.03916.01
5.4.420.0050.03516.14
5.4.410.0050.02516.03
5.4.400.0050.03715.98
5.4.390.0020.03915.95
5.4.380.0090.02316.07
5.4.370.0030.03415.94
5.4.360.0030.02715.94
5.4.350.0000.04715.93
5.4.340.0120.02816.04
5.4.330.0040.00412.84
5.4.320.0020.04815.92
5.4.310.0050.04215.89
5.4.300.0040.02916.01
5.4.290.0080.04216.00
5.4.280.0050.04016.00
5.4.270.0120.03216.02
5.4.260.0100.02816.04
5.4.250.0030.04315.96
5.4.240.0000.02815.97
5.4.230.0030.04215.97
5.4.220.0050.02315.93
5.4.210.0070.03715.86
5.4.200.0070.04015.99
5.4.190.0070.04516.02
5.4.180.0060.03815.89
5.4.170.0100.03715.89
5.4.160.0070.03915.93
5.4.150.0010.04315.85
5.4.140.0050.03814.63
5.4.130.0050.03514.62
5.4.120.0030.03514.63
5.4.110.0030.02514.70
5.4.100.0110.03514.62
5.4.90.0030.03914.70
5.4.80.0030.02514.63
5.4.70.0030.03314.65
5.4.60.0020.04214.66
5.4.50.0080.03314.60
5.4.40.0060.03414.59
5.4.30.0030.03014.64
5.4.20.0010.02614.67
5.4.10.0070.02214.65
5.4.00.0080.02814.25
5.3.290.0060.02313.78
5.3.280.0050.03413.74
5.3.270.0050.04313.81
5.3.260.0030.04213.76
5.3.250.0020.02613.72
5.3.240.0080.03813.71
5.3.230.0050.04213.71
5.3.220.0070.03713.75
5.3.210.0050.04313.75
5.3.200.0070.03813.78
5.3.190.0090.03713.78
5.3.180.0080.03813.77
5.3.170.0020.04113.69
5.3.160.0030.04713.76
5.3.150.0050.02213.72
5.3.140.0050.03213.75
5.3.130.0120.03413.79
5.3.120.0030.03513.75
5.3.110.0050.02613.79
5.3.100.0070.02113.47
5.3.90.0050.03513.51
5.3.80.0080.02813.47
5.3.70.0070.03613.40
5.3.60.0030.03313.51
5.3.50.0070.02313.47
5.3.40.0020.03113.46
5.3.30.0060.02013.43
5.3.20.0020.04313.30
5.3.10.0080.03313.33
5.3.00.0050.02213.27
5.2.170.0000.04311.18
5.2.160.0130.03011.34
5.2.150.0000.04711.18
5.2.140.0200.04711.22
5.2.130.0070.05711.23
5.2.120.0070.03711.20
5.2.110.0100.02711.09
5.2.100.0100.04311.17
5.2.90.0070.02311.14
5.2.80.0030.06011.25
5.2.70.0070.05711.04
5.2.60.0030.05011.04
5.2.50.0100.05310.96
5.2.40.0070.06011.11
5.2.30.0100.05011.11
5.2.20.0170.02310.98
5.2.10.0000.06011.05
5.2.00.0070.06010.88
5.1.60.0070.02710.05
5.1.50.0000.03710.12
5.1.40.0030.03010.04
5.1.30.0100.05010.53
5.1.20.0130.04310.46
5.1.10.0000.03010.12
5.1.00.0000.02710.12
5.0.50.0030.0378.45
5.0.40.0070.0308.44
5.0.30.0070.0478.44
5.0.20.0000.0378.44
5.0.10.0070.0408.44
5.0.00.0100.0508.44
4.4.90.0000.0378.44
4.4.80.0000.0178.44
4.4.70.0070.0338.44
4.4.60.0000.0378.44
4.4.50.0000.0378.44
4.4.40.0070.0438.44
4.4.30.0030.0208.44
4.4.20.0000.0278.44
4.4.10.0000.0338.44
4.4.00.0070.0238.44
4.3.110.0070.0338.44
4.3.100.0000.0208.44
4.3.90.0030.0238.44
4.3.80.0070.0338.44
4.3.70.0000.0378.44
4.3.60.0070.0178.44
4.3.50.0030.0278.44
4.3.40.0000.0308.44
4.3.30.0000.0178.44
4.3.20.0030.0308.44
4.3.10.0000.0208.44
4.3.00.0000.0208.44

preferences:
40.67 ms | 401 KiB | 5 Q