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 IllegalStateException("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 = '+++++++++ +++++++++ +++++++++ + > +++++++++ +++++++++ +++++++++ ++ < . < .'; $c->execute($bf); ?>

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.00618.63
8.3.50.0120.00522.16
8.3.40.0170.00318.92
8.3.30.0070.00720.26
8.3.20.0050.00320.38
8.3.10.0040.00421.79
8.3.00.0040.00420.77
8.2.180.0070.01416.38
8.2.170.0070.00722.96
8.2.160.0160.00319.27
8.2.150.0030.00524.18
8.2.140.0070.01424.66
8.2.130.0090.00926.16
8.2.120.0040.00419.66
8.2.110.0060.00320.57
8.2.100.0120.00017.97
8.2.90.0000.00819.36
8.2.80.0030.00519.44
8.2.70.0030.00517.75
8.2.60.0050.00318.04
8.2.50.0000.00918.07
8.2.40.0000.00918.16
8.2.30.0030.00518.21
8.2.20.0040.00417.73
8.2.10.0090.00017.93
8.2.00.0030.00617.91
8.1.280.0070.00725.92
8.1.270.0050.00324.66
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0030.00623.95
8.1.230.0040.00719.25
8.1.220.0060.00317.79
8.1.210.0060.00318.77
8.1.200.0030.00617.48
8.1.190.0050.00317.65
8.1.180.0030.00619.01
8.1.170.0040.00418.68
8.1.160.0000.00722.18
8.1.150.0040.00418.71
8.1.140.0030.00617.57
8.1.130.0000.00717.77
8.1.120.0080.00017.56
8.1.110.0050.00217.48
8.1.100.0030.00517.50
8.1.90.0000.00817.55
8.1.80.0040.00417.58
8.1.70.0040.00417.43
8.1.60.0030.00617.63
8.1.50.0030.00517.64
8.1.40.0050.00317.64
8.1.30.0030.00517.64
8.1.20.0030.00617.71
8.1.10.0000.00817.60
8.1.00.0000.00917.58
8.0.300.0040.00418.77
8.0.290.0090.00017.29
8.0.280.0000.00718.57
8.0.270.0050.00217.38
8.0.260.0070.00016.91
8.0.250.0000.00717.04
8.0.240.0030.00516.97
8.0.230.0070.00017.11
8.0.220.0040.00417.07
8.0.210.0000.00817.05
8.0.200.0000.00617.14
8.0.190.0040.00417.09
8.0.180.0050.00517.10
8.0.170.0020.00517.04
8.0.160.0040.00417.04
8.0.150.0000.00716.99
8.0.140.0000.00816.98
8.0.130.0060.00013.43
8.0.120.0040.00417.02
8.0.110.0040.00416.96
8.0.100.0050.00317.04
8.0.90.0000.00716.89
8.0.80.0060.01217.03
8.0.70.0050.00316.99
8.0.60.0030.00516.93
8.0.50.0050.00217.09
8.0.30.0150.00617.24
8.0.20.0080.01217.40
8.0.10.0050.00217.12
8.0.00.0120.00617.01
7.4.330.0000.00615.00
7.4.320.0060.00016.57
7.4.300.0030.00316.59
7.4.290.0000.00716.59
7.4.280.0080.00016.60
7.4.270.0030.00316.66
7.4.260.0000.00816.55
7.4.250.0040.00416.68
7.4.240.0040.00316.65
7.4.230.0000.00716.66
7.4.220.0120.00616.66
7.4.210.0060.01016.65
7.4.200.0000.00716.40
7.4.190.0040.00416.64
7.4.160.0090.00616.59
7.4.150.0090.00917.40
7.4.140.0110.01017.86
7.4.130.0110.00616.58
7.4.120.0150.00316.51
7.4.110.0220.00316.73
7.4.100.0080.01216.72
7.4.90.0090.00916.59
7.4.80.0050.01119.39
7.4.70.0140.00316.41
7.4.60.0100.00716.48
7.4.50.0000.00616.73
7.4.40.0070.00722.77
7.4.30.0160.00616.70
7.4.10.0090.01115.12
7.4.00.0080.00715.03
7.3.330.0020.00313.47
7.3.320.0030.00313.36
7.3.310.0040.00416.32
7.3.300.0030.00316.42
7.3.290.0100.01016.54
7.3.280.0080.00916.53
7.3.270.0150.00817.40
7.3.260.0170.00416.48
7.3.250.0130.00416.57
7.3.240.0110.00516.50
7.3.230.0070.01016.73
7.3.210.0140.00716.74
7.3.200.0100.00719.39
7.3.190.0130.00316.71
7.3.180.0080.00816.71
7.3.170.0060.01016.62
7.3.160.0150.00016.47
7.3.130.0020.01414.96
7.3.120.0050.01314.91
7.3.110.0070.01114.83
7.3.100.0110.00614.88
7.3.90.0030.01414.95
7.3.80.0080.00514.83
7.3.70.0080.00714.88
7.3.60.0040.00714.89
7.3.50.0050.00914.81
7.3.40.0070.00514.79
7.3.30.0000.00914.82
7.3.20.0110.00216.61
7.3.10.0100.00716.57
7.3.00.0070.00616.87
7.2.330.0040.01416.90
7.2.320.0100.01316.56
7.2.310.0090.00916.68
7.2.300.0200.00016.88
7.2.290.0100.00716.92
7.2.260.0070.01215.12
7.2.250.0070.01415.02
7.2.240.0090.00615.23
7.2.230.0080.01015.07
7.2.220.0080.00615.16
7.2.210.0050.00415.06
7.2.200.0050.01015.05
7.2.190.0080.00715.16
7.2.180.0060.00715.06
7.2.170.0070.00515.06
7.2.160.0090.00614.88
7.2.150.0080.00816.90
7.2.140.0090.00716.94
7.2.130.0050.00916.90
7.2.120.0020.00917.00
7.2.110.0010.01116.81
7.2.100.0060.00716.84
7.2.90.0050.00717.05
7.2.80.0060.01016.84
7.2.70.0070.00916.91
7.2.60.0020.01216.97
7.2.50.0070.00316.96
7.2.40.0040.00916.94
7.2.30.0060.00817.01
7.2.20.0050.01016.73
7.2.10.0020.01116.93
7.2.00.0030.01117.74
7.1.330.0070.01015.80
7.1.320.0130.00315.81
7.1.310.0020.01115.93
7.1.300.0050.01215.75
7.1.290.0050.00815.69
7.1.280.0030.01115.86
7.1.270.0020.00815.94
7.1.260.0070.00715.94
7.1.250.0050.00815.61
7.1.240.0050.00715.97
7.1.230.0050.00715.75
7.1.220.0040.00815.90
7.1.210.0070.00515.87
7.1.200.0080.00315.78
7.1.190.0060.00616.00
7.1.180.0040.01215.75
7.1.170.0070.00815.71
7.1.160.0070.00515.73
7.1.150.0050.00715.81
7.1.140.0020.00815.77
7.1.130.0060.00815.69
7.1.120.0030.01115.72
7.1.110.0050.00715.86
7.1.100.0050.00716.59
7.1.90.0020.01215.75
7.1.80.0070.00815.86
7.1.70.0050.00716.27
7.1.60.0090.00717.00
7.1.50.0080.00615.42
7.1.40.0030.01015.78
7.1.30.0030.00815.56
7.1.20.0090.00415.68
7.1.10.0050.00915.64
7.1.00.0100.02018.09
7.0.330.0050.00515.31
7.0.320.0030.00815.44
7.0.310.0030.01015.38
7.0.300.0080.00515.34
7.0.290.0050.00615.35
7.0.280.0050.00815.25
7.0.270.0060.00315.40
7.0.260.0060.00515.22
7.0.250.0020.01115.45
7.0.240.0030.00815.40
7.0.230.0100.00515.42
7.0.220.0060.00715.45
7.0.210.0030.00715.43
7.0.200.0110.00715.20
7.0.190.0100.00515.27
7.0.180.0060.00915.39
7.0.170.0050.00815.38
7.0.160.0040.00815.38
7.0.150.0020.01315.46
7.0.140.0090.02717.68
7.0.130.0060.00315.39
7.0.120.0060.00715.38
7.0.110.0100.00315.34
7.0.100.0070.02316.89
7.0.90.0030.02716.97
7.0.80.0080.02717.05
7.0.70.0100.02717.01
7.0.60.0110.02916.72
7.0.50.0040.03417.05
7.0.40.0120.01315.63
7.0.30.0070.03415.61
7.0.20.0070.02015.53
7.0.10.0090.02215.69
7.0.00.0060.03215.57
5.6.400.0030.00714.68
5.6.390.0010.01114.64
5.6.380.0040.00614.38
5.6.370.0030.00814.56
5.6.360.0020.01014.58
5.6.350.0080.00514.71
5.6.340.0060.00614.31
5.6.330.0030.00814.48
5.6.320.0030.01214.74
5.6.310.0020.01014.76
5.6.300.0030.01014.50
5.6.290.0050.00914.40
5.6.280.0080.02816.84
5.6.270.0030.01214.54
5.6.260.0060.00714.59
5.6.250.0070.02216.54
5.6.240.0060.02416.59
5.6.230.0020.03316.73
5.6.220.0040.03016.50
5.6.210.0080.02916.60
5.6.200.0090.03116.63
5.6.190.0120.03016.61
5.6.180.0080.02816.62
5.6.170.0060.02616.65
5.6.160.0080.02916.75
5.6.150.0050.03016.70
5.6.140.0030.02216.82
5.6.130.0110.01416.81
5.6.120.0030.03616.83
5.6.110.0070.02216.61
5.6.100.0060.03216.62
5.6.90.0060.03316.68
5.6.80.0090.02616.46
5.6.70.0010.02616.45
5.6.60.0060.01916.32
5.6.50.0060.01616.56
5.6.40.0060.01716.46
5.6.30.0090.01716.43
5.6.20.0060.01616.43
5.6.10.0040.02216.40
5.6.00.0060.01716.34
5.5.380.0060.03116.42
5.5.370.0070.03316.39
5.5.360.0060.03016.41
5.5.350.0060.03116.51
5.5.340.0050.03416.65
5.5.330.0110.02516.45
5.5.320.0040.03216.39
5.5.310.0050.02716.45
5.5.300.0080.02116.58
5.5.290.0100.03216.55
5.5.280.0070.02516.57
5.5.270.0010.03516.63
5.5.260.0060.03216.61
5.5.250.0070.03416.47
5.5.240.0030.02516.30
5.5.230.0040.01816.24
5.5.220.0040.02116.31
5.5.210.0040.01816.32
5.5.200.0070.01616.40
5.5.190.0040.01816.24
5.5.180.0040.02016.49
5.5.170.0070.00914.31
5.5.160.0060.01516.38
5.5.150.0050.01616.23
5.5.140.0070.01716.38
5.5.130.0100.01716.34
5.5.120.0040.02016.24
5.5.110.0060.01616.38
5.5.100.0040.01516.35
5.5.90.0070.01816.26
5.5.80.0050.02116.31
5.5.70.0060.01916.34
5.5.60.0030.01616.23
5.5.50.0080.01616.14
5.5.40.0050.01916.23
5.5.30.0030.02216.19
5.5.20.0100.01316.19
5.5.10.0040.02316.21
5.5.00.0050.01616.24
5.4.450.0030.02414.02
5.4.440.0110.03013.98
5.4.430.0050.03014.00
5.4.420.0040.02714.01
5.4.410.0060.02113.99
5.4.400.0050.01713.86
5.4.390.0070.01413.91
5.4.380.0040.02113.80
5.4.370.0030.01813.78
5.4.360.0060.01513.83
5.4.350.0020.02113.78
5.4.340.0030.01513.76
5.4.330.0060.00711.29
5.4.320.0030.01913.87
5.4.310.0040.01513.95
5.4.300.0020.01913.80
5.4.290.0050.01613.75
5.4.280.0050.01613.90
5.4.270.0070.02313.69
5.4.260.0020.01813.78
5.4.250.0030.01813.86
5.4.240.0010.02013.75
5.4.230.0050.01513.74
5.4.220.0060.01513.74
5.4.210.0080.01713.60
5.4.200.0060.01813.72
5.4.190.0090.01113.86
5.4.180.0050.01413.77
5.4.170.0020.01813.77
5.4.160.0050.01513.79
5.4.150.0010.02113.76
5.4.140.0020.01813.01
5.4.130.0070.01512.87
5.4.120.0070.01312.96
5.4.110.0070.01212.89
5.4.100.0010.01612.84
5.4.90.0040.01812.83
5.4.80.0010.01812.96
5.4.70.0010.01612.81
5.4.60.0030.01712.82
5.4.50.0050.01413.00
5.4.40.0100.02312.95
5.4.30.0020.02212.84
5.4.20.0000.02512.97
5.4.10.0020.01812.95
5.4.00.0070.02512.53
5.3.290.0070.01312.11
5.3.280.0030.01712.03
5.3.270.0030.01811.99
5.3.260.0060.01511.89
5.3.250.0060.01611.99
5.3.240.0080.01412.02
5.3.230.0050.01312.01
5.3.220.0050.01611.95
5.3.210.0030.01611.95
5.3.200.0050.01512.03
5.3.190.0020.01711.98
5.3.180.0020.01612.18
5.3.170.0000.01611.97
5.3.160.0030.01612.12
5.3.150.0040.02012.02
5.3.140.0030.02612.06
5.3.130.0040.01711.87
5.3.120.0030.02412.11
5.3.110.0070.02712.12
5.3.100.0010.02011.94
5.3.90.0030.02911.68
5.3.80.0020.02411.78
5.3.70.0040.03111.83
5.3.60.0060.01811.78
5.3.50.0050.01611.72
5.3.40.0040.02511.73
5.3.30.0030.01711.72
5.3.20.0030.02611.55
5.3.10.0070.02111.49
5.3.00.0050.02711.49
5.2.170.0030.04713.17
5.2.160.0130.05013.17
5.2.150.0100.05313.17
5.2.140.0000.06313.17
5.2.130.0000.04013.17
5.2.120.0030.06013.17
5.2.110.0030.06713.17
5.2.100.0030.04713.17
5.2.90.0070.04013.17
5.2.80.0000.04313.17
5.2.70.0070.04713.17
5.2.60.0100.05313.17
5.2.50.0070.05313.17
5.2.40.0070.03713.17
5.2.30.0070.05013.17
5.2.20.0000.04713.17
5.2.10.0030.05013.17
5.2.00.0100.05713.17
5.1.60.0030.04713.17
5.1.50.0100.04713.17
5.1.40.0070.04313.17
5.1.30.0030.03013.17
5.1.20.0000.03313.17
5.1.10.0070.04013.17
5.1.00.0030.03313.17
5.0.50.0030.05013.17
5.0.40.0070.02313.17
5.0.30.0000.04313.17
5.0.20.0030.02313.17
5.0.10.0100.03713.17
5.0.00.0030.05713.17
4.4.90.0000.03713.17
4.4.80.0030.03313.17
4.4.70.0030.03013.17
4.4.60.0030.03713.17
4.4.50.0000.03313.17
4.4.40.0030.04313.17
4.4.30.0000.03013.17
4.4.20.0000.02713.17
4.4.10.0030.03313.17
4.4.00.0030.03313.17
4.3.110.0030.03313.17
4.3.100.0000.02713.17
4.3.90.0100.01013.17
4.3.80.0000.02713.17
4.3.70.0030.03313.17
4.3.60.0030.02713.17
4.3.50.0070.01313.17
4.3.40.0030.03013.17
4.3.30.0030.03313.17
4.3.20.0000.03313.17
4.3.10.0000.02313.17
4.3.00.0000.03313.17

preferences:
44.72 ms | 401 KiB | 5 Q