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; } public function getCells() { return $this->arr; } public function getPointer() { return $this->ptr; } } $c = new Compiler(); $bf = '+++++++++ +++++++++ +++++++++ + > +++++++++ +++++++++ +++++++++ ++ < . < .'; try { $c->execute($bf); } catch (Exception $e) { echo PHP_EOL."An exception was thrown whilst processing your BF program.".PHP_EOL; echo $e->getMessage().":".PHP_EOL; echo "The pointer was set to ".$c->getPointer()." and the cell array resembled:".PHP_EOL; echo "[".implode(", ", $c->getCells())."]".PHP_EOL; echo "The current stack trace was:".PHP_EOL; $i = 0; foreach ($c->getCallStack() as $call) { echo '#'.$i.' '.$call['command'].' ('.$call['internal_function'],') on pos '.$call['pos'].PHP_EOL; } } echo PHP_EOL.'Finished.'.PHP_EOL; ?>

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.70.0090.00918.77
8.3.60.0100.01018.81
8.3.50.0110.00621.14
8.3.40.0120.00319.14
8.3.30.0140.00020.17
8.3.20.0090.00020.25
8.3.10.0080.00021.96
8.3.00.0040.00420.67
8.2.180.0170.00316.88
8.2.170.0100.00619.04
8.2.160.0120.00922.96
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00419.66
8.2.110.0040.00422.08
8.2.100.0070.00419.76
8.2.90.0060.00319.17
8.2.80.0040.00419.34
8.2.70.0000.00917.75
8.2.60.0060.00317.93
8.2.50.0040.00418.07
8.2.40.0000.00818.09
8.2.30.0000.01218.28
8.2.20.0080.00017.87
8.2.10.0040.00417.89
8.2.00.0040.00417.94
8.1.280.0030.01425.92
8.1.270.0090.00022.25
8.1.260.0060.00326.35
8.1.250.0030.00628.09
8.1.240.0090.00023.80
8.1.230.0030.00719.13
8.1.220.0000.00917.80
8.1.210.0040.00418.77
8.1.200.0030.00617.48
8.1.190.0040.00417.79
8.1.180.0080.00018.98
8.1.170.0060.00318.59
8.1.160.0050.00222.12
8.1.150.0050.00218.58
8.1.140.0000.00717.58
8.1.130.0030.00317.91
8.1.120.0000.00717.57
8.1.110.0040.00417.45
8.1.100.0000.00717.58
8.1.90.0000.00717.42
8.1.80.0040.00417.55
8.1.70.0000.00717.46
8.1.60.0060.00317.67
8.1.50.0040.00417.60
8.1.40.0000.00917.60
8.1.30.0050.00317.68
8.1.20.0000.00917.79
8.1.10.0030.00617.68
8.1.00.0000.01117.57
8.0.300.0040.00418.77
8.0.290.0000.00717.30
8.0.280.0030.00518.37
8.0.270.0040.00417.33
8.0.260.0030.00316.95
8.0.250.0030.00317.16
8.0.240.0050.00317.13
8.0.230.0040.00416.91
8.0.220.0040.00416.99
8.0.210.0040.00416.91
8.0.200.0040.00417.12
8.0.190.0050.00317.00
8.0.180.0080.00017.02
8.0.170.0050.00317.04
8.0.160.0070.00017.00
8.0.150.0070.00017.05
8.0.140.0040.00416.87
8.0.130.0000.00713.50
8.0.120.0050.00317.03
8.0.110.0070.00016.95
8.0.100.0040.00417.09
8.0.90.0070.00017.07
8.0.80.0070.01416.95
8.0.70.0000.00717.02
8.0.60.0000.00717.02
8.0.50.0040.00417.02
8.0.30.0090.01017.14
8.0.20.0080.01117.42
8.0.10.0000.00717.19
8.0.00.0090.01416.96
7.4.330.0030.00315.00
7.4.320.0030.00316.69
7.4.300.0030.00316.55
7.4.290.0030.00316.68
7.4.280.0030.00316.66
7.4.270.0000.00716.53
7.4.260.0080.00316.60
7.4.250.0040.00416.59
7.4.240.0020.00616.50
7.4.230.0030.00316.71
7.4.220.0100.01016.76
7.4.210.0090.00716.67
7.4.200.0070.00016.69
7.4.190.0060.00316.44
7.4.160.0050.01116.55
7.4.150.0150.00317.40
7.4.140.0030.01417.86
7.4.130.0090.01016.62
7.4.120.0070.00916.63
7.4.110.0070.01016.47
7.4.100.0040.01316.59
7.4.90.0120.00816.61
7.4.80.0130.00319.39
7.4.70.0120.00416.57
7.4.60.0090.00916.67
7.4.50.0080.00016.66
7.4.40.0100.00622.77
7.4.30.0160.00316.50
7.4.00.0070.01015.31
7.3.330.0030.00313.50
7.3.320.0000.00613.45
7.3.310.0070.00016.55
7.3.300.0000.00716.36
7.3.290.0090.01216.48
7.3.280.0060.01016.47
7.3.270.0180.00417.40
7.3.260.0110.00716.70
7.3.250.0110.00616.56
7.3.240.0060.01216.65
7.3.230.0160.00816.63
7.3.210.0130.00416.53
7.3.200.0080.00819.39
7.3.190.0180.00616.45
7.3.180.0060.01016.62
7.3.170.0060.00916.58
7.3.160.0140.00716.68
7.3.120.0060.00615.05
7.3.10.0070.01016.52
7.3.00.0060.00316.66
7.2.330.0120.00616.90
7.2.320.0090.00916.58
7.2.310.0090.00916.77
7.2.300.0130.00316.60
7.2.290.0100.01316.73
7.2.130.0080.00816.90
7.2.120.0030.01016.99
7.2.110.0110.00317.07
7.2.100.0090.00616.78
7.2.90.0040.01216.76
7.2.80.0040.00717.08
7.2.70.0070.00717.21
7.2.60.0080.00316.98
7.2.50.0070.00716.91
7.2.40.0030.01217.12
7.2.30.0070.00716.77
7.2.20.0060.00916.73
7.2.10.0000.01116.81
7.2.00.0040.00818.16
7.1.250.0080.00015.87
7.1.240.0000.01015.73
7.1.230.0110.00415.93
7.1.220.0030.01015.66
7.1.210.0000.00815.68
7.1.200.0040.00915.68
7.1.190.0060.00315.67
7.1.180.0080.00315.92
7.1.170.0060.00615.98
7.1.160.0030.01015.64
7.1.150.0030.00915.77
7.1.140.0000.00915.97
7.1.130.0030.01315.92
7.1.120.0000.01515.88
7.1.110.0070.00715.56
7.1.100.0050.00816.81
7.1.90.0000.01215.84
7.1.80.0040.00715.68
7.1.70.0030.00716.33
7.1.60.0040.01617.61
7.1.50.0030.01216.56
7.1.40.0060.00615.98
7.1.30.0000.01415.88
7.1.20.0100.00615.82
7.1.10.0070.00715.70
7.1.00.0070.03719.08
7.0.330.0060.00615.43
7.0.320.0070.00715.41
7.0.310.0090.00615.29
7.0.300.0070.00715.16
7.0.290.0070.00715.33
7.0.280.0030.00915.39
7.0.270.0030.01015.14
7.0.260.0090.00015.32
7.0.250.0110.00315.19
7.0.240.0100.00615.48
7.0.230.0140.00015.44
7.0.220.0090.00615.50
7.0.210.0040.01115.61
7.0.200.0110.01015.13
7.0.190.0030.00915.52
7.0.180.0100.00315.54
7.0.170.0110.00815.43
7.0.160.0060.00315.52
7.0.150.0000.01615.30
7.0.140.0000.04718.69
7.0.130.0100.00315.14
7.0.120.0030.00715.23
7.0.110.0060.00615.56
7.0.100.0090.01817.69
7.0.90.0070.03017.66
7.0.80.0100.02817.62
7.0.70.0080.04017.57
7.0.60.0080.04217.95
7.0.50.0050.04318.21
7.0.40.0100.04317.10
7.0.30.0050.04716.96
7.0.20.0030.05116.99
7.0.10.0070.03517.00
7.0.00.0110.04317.02
5.6.380.0030.00614.66
5.6.370.0090.00614.40
5.6.360.0040.01114.30
5.6.350.0060.01214.47
5.6.340.0000.00814.39
5.6.330.0000.00914.53
5.6.320.0090.00314.59
5.6.310.0090.00514.45
5.6.300.0130.00014.55
5.6.290.0040.00414.54
5.6.280.0030.01114.84
5.6.270.0000.01314.52
5.6.260.0000.01314.86
5.6.250.0140.03417.55
5.6.240.0060.04917.63
5.6.230.0080.03617.57
5.6.220.0100.04117.50
5.6.210.0030.05217.44
5.6.200.0070.02517.72
5.6.190.0040.05017.82
5.6.180.0050.04917.64
5.6.170.0050.05017.66
5.6.160.0120.03817.75
5.6.150.0100.04517.89
5.6.140.0070.03917.72
5.6.130.0030.03317.87
5.6.120.0030.04717.84
5.6.110.0020.05417.74
5.6.100.0080.04517.79
5.6.90.0160.04017.70
5.6.80.0040.02917.49
5.6.70.0070.02217.40
5.6.60.0080.02117.39
5.6.50.0060.02317.49
5.6.40.0070.02317.40
5.6.30.0080.03517.42
5.6.20.0050.04117.37
5.6.10.0080.02017.43
5.6.00.0050.02317.42
5.5.380.0130.04015.87
5.5.370.0100.03815.75
5.5.360.0060.04615.88
5.5.350.0080.04715.98
5.5.340.0050.04216.05
5.5.330.0070.04616.24
5.5.320.0030.04715.96
5.5.310.0070.04715.98
5.5.300.0080.04416.11
5.5.290.0050.03316.03
5.5.280.0080.03616.14
5.5.270.0080.04016.10
5.5.260.0070.02015.93
5.5.250.0050.02616.00
5.5.240.0030.02515.80
5.5.230.0060.02115.59
5.5.220.0080.02215.60
5.5.210.0060.02015.74
5.5.200.0020.02315.77
5.5.190.0070.02015.76
5.5.180.0040.02315.67
5.5.170.0100.00311.33
5.5.160.0070.04215.78
5.5.150.0120.04015.73
5.5.140.0050.04215.85
5.5.130.0050.02215.59
5.5.120.0050.02015.69
5.5.110.0100.02815.80
5.5.100.0020.02615.67
5.5.90.0060.03115.66
5.5.80.0030.02515.72
5.5.70.0040.04315.53
5.5.60.0070.01815.81
5.5.50.0030.03315.70
5.5.40.0050.02315.73
5.5.30.0030.02715.65
5.5.20.0000.03115.51
5.5.10.0020.02515.55
5.5.00.0050.02015.47
5.4.450.0090.03515.47
5.4.440.0070.03515.31
5.4.430.0020.03915.31
5.4.420.0050.04215.41
5.4.410.0050.02515.37
5.4.400.0070.01815.05
5.4.390.0080.02115.13
5.4.380.0030.02215.07
5.4.370.0070.01915.14
5.4.360.0070.02015.26
5.4.350.0030.02015.23
5.4.340.0050.04215.19
5.4.330.0030.01011.23
5.4.320.0030.02714.96
5.4.310.0140.03515.18
5.4.300.0100.02215.12
5.4.290.0070.03815.17
5.4.280.0050.03315.15
5.4.270.0020.02415.18
5.4.260.0040.02615.13
5.4.250.0030.02215.14
5.4.240.0150.03315.12
5.4.230.0070.02515.11
5.4.220.0070.02215.21
5.4.210.0080.02415.09
5.4.200.0040.02915.04
5.4.190.0030.03415.04
5.4.180.0080.02015.07
5.4.170.0050.02215.17
5.4.160.0030.03915.13
5.4.150.0020.02415.12
5.4.140.0020.02213.88
5.4.130.0060.02313.77
5.4.120.0050.02014.01
5.4.110.0020.02513.89
5.4.100.0020.02513.87
5.4.90.0050.02713.89
5.4.80.0040.01913.77
5.4.70.0040.01913.91
5.4.60.0030.02213.83
5.4.50.0020.02213.89
5.4.40.0060.03813.82
5.4.30.0050.03013.89
5.4.20.0070.03313.75
5.4.10.0100.03213.89
5.4.00.0050.03513.57
5.3.290.0050.04412.82
5.3.280.0040.02412.71
5.3.270.0090.02012.70
5.3.260.0010.02312.73
5.3.250.0020.02312.73
5.3.240.0000.02612.64
5.3.230.0000.02712.74
5.3.220.0000.02412.68
5.3.210.0030.02112.66
5.3.200.0100.02812.72
5.3.190.0050.02112.65
5.3.180.0050.02012.69
5.3.170.0020.02312.69
5.3.160.0080.03512.68
5.3.150.0070.01712.71
5.3.140.0010.02412.65
5.3.130.0050.02012.73
5.3.120.0040.04112.66
5.3.110.0020.04712.73
5.3.100.0020.02012.48
5.3.90.0000.04412.48
5.3.80.0030.02812.33
5.3.70.0000.02312.40
5.3.60.0040.03912.42
5.3.50.0050.03212.38
5.3.40.0050.03512.41
5.3.30.0030.02612.37
5.3.20.0100.02512.17
5.3.10.0050.04012.24
5.3.00.0050.03912.14

preferences:
51.14 ms | 401 KiB | 5 Q