3v4l.org

run code in 300+ PHP versions simultaneously
<?PHP if (!class_exists('RuntimeException')) { class RuntimeException extends Exception { } } 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 'hey'.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 { echo "{ "; $c->execute($bf); echo " }"; } 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.60.0030.01418.68
8.3.50.0160.00621.27
8.3.40.0110.00418.77
8.3.30.0070.00720.34
8.3.20.0000.00820.18
8.3.10.0040.00421.90
8.3.00.0040.00422.35
8.2.180.0080.00818.17
8.2.170.0140.00422.96
8.2.160.0100.00322.08
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0040.00420.74
8.2.110.0090.00022.14
8.2.100.0070.00417.97
8.2.90.0030.00619.47
8.2.80.0000.00819.36
8.2.70.0000.00817.63
8.2.60.0060.00318.16
8.2.50.0060.00318.07
8.2.40.0000.00818.18
8.2.30.0050.00219.71
8.2.20.0050.00317.76
8.2.10.0090.00017.90
8.2.00.0000.00817.74
8.1.270.0040.00423.99
8.1.260.0040.00426.35
8.1.250.0030.00628.09
8.1.240.0060.00323.82
8.1.230.0040.00819.21
8.1.220.0000.00817.74
8.1.210.0050.00518.77
8.1.200.0060.00317.47
8.1.190.0000.00817.75
8.1.180.0000.00818.10
8.1.170.0000.00918.71
8.1.160.0000.00718.96
8.1.150.0060.00318.63
8.1.140.0000.00817.52
8.1.130.0040.00417.80
8.1.120.0040.00417.52
8.1.110.0040.00417.45
8.1.100.0040.00417.45
8.1.90.0000.00717.53
8.1.80.0040.00417.45
8.1.70.0050.00217.48
8.1.60.0030.00617.74
8.1.50.0030.00617.63
8.1.40.0080.00017.49
8.1.30.0030.00517.68
8.1.20.0030.00617.58
8.1.10.0000.00917.66
8.1.00.0040.00417.61
8.0.300.0050.00218.77
8.0.290.0040.00417.18
8.0.280.0040.00418.42
8.0.270.0030.00317.41
8.0.260.0030.00316.86
8.0.250.0030.00317.08
8.0.240.0040.00416.91
8.0.230.0000.00817.04
8.0.220.0000.00816.95
8.0.210.0030.00516.99
8.0.200.0030.00316.96
8.0.190.0040.00417.04
8.0.180.0000.00716.86
8.0.170.0040.00417.01
8.0.160.0070.00016.98
8.0.150.0000.00716.91
8.0.140.0080.00016.87
8.0.130.0060.00013.45
8.0.120.0080.00016.96
8.0.110.0070.00017.00
8.0.100.0000.00816.88
8.0.90.0050.00217.00
8.0.80.0060.01616.99
8.0.70.0030.00517.00
8.0.60.0040.00416.98
8.0.50.0070.00016.79
8.0.30.0090.01317.03
8.0.20.0110.01017.40
8.0.10.0040.00417.00
8.0.00.0120.00816.86
7.4.330.0050.00016.79
7.4.320.0040.00416.71
7.4.300.0030.00316.58
7.4.290.0040.00416.61
7.4.280.0040.00416.69
7.4.270.0050.00316.61
7.4.260.0050.00013.38
7.4.250.0000.00816.64
7.4.240.0020.00516.67
7.4.230.0000.00716.66
7.4.220.0110.00816.63
7.4.210.0080.00716.57
7.4.200.0000.00816.60
7.4.190.0000.00716.57
7.4.160.0180.00616.59
7.4.150.0030.01317.40
7.4.140.0100.00917.86
7.4.130.0130.00516.49
7.4.120.0120.00716.52
7.4.110.0140.00416.54
7.4.100.0180.00516.66
7.4.90.0140.00316.49
7.4.80.0190.00519.39
7.4.70.0070.01016.70
7.4.60.0150.00316.38
7.4.50.0000.00816.66
7.4.40.0000.01722.77
7.4.30.0060.01516.53
7.4.10.0090.00915.16
7.4.00.0060.00914.88
7.3.330.0000.00613.41
7.3.320.0000.00513.38
7.3.310.0040.00416.48
7.3.300.0030.00316.41
7.3.290.0120.00316.52
7.3.280.0110.00816.48
7.3.270.0140.00317.40
7.3.260.0060.01216.40
7.3.250.0090.01016.54
7.3.240.0160.00616.69
7.3.230.0130.01016.39
7.3.210.0080.00816.71
7.3.200.0100.01319.39
7.3.190.0100.01316.67
7.3.180.0070.01016.71
7.3.170.0120.00616.49
7.3.160.0120.00416.54
7.3.130.0080.00714.62
7.3.120.0100.00715.03
7.3.110.0070.01115.05
7.3.100.0070.00714.66
7.3.90.0100.00615.18
7.3.80.0030.00714.91
7.3.70.0040.01214.91
7.3.60.0040.00814.86
7.3.50.0030.00714.71
7.3.40.0030.01014.98
7.3.30.0070.00414.92
7.3.20.0070.01016.87
7.3.10.0090.00016.75
7.3.00.0070.00716.59
7.2.330.0100.01016.81
7.2.320.0130.01016.89
7.2.310.0150.00316.88
7.2.300.0120.00616.91
7.2.290.0090.01216.63
7.2.260.0090.01015.12
7.2.250.0060.01315.23
7.2.240.0000.01415.02
7.2.230.0040.01114.89
7.2.220.0090.00315.44
7.2.210.0000.01015.18
7.2.200.0130.00315.21
7.2.190.0030.00715.15
7.2.180.0090.00615.31
7.2.170.0060.00314.98
7.2.160.0060.00915.24
7.2.150.0100.00316.91
7.2.140.0060.00616.96
7.2.130.0030.01416.96
7.2.120.0090.00617.02
7.2.110.0030.00916.92
7.2.100.0030.01316.78
7.2.90.0070.00416.91
7.2.80.0100.00516.68
7.2.70.0100.00717.10
7.2.60.0050.01017.09
7.2.50.0100.00716.93
7.2.40.0060.00616.69
7.2.30.0060.00616.64
7.2.20.0070.00716.75
7.2.10.0070.00716.97
7.2.00.0050.01118.12
7.1.330.0070.00715.63
7.1.320.0050.00516.00
7.1.310.0090.00315.78
7.1.300.0030.01015.68
7.1.290.0000.00915.78
7.1.280.0030.00615.53
7.1.270.0030.01215.74
7.1.260.0100.00315.87
7.1.250.0030.01015.72
7.1.240.0030.01015.91
7.1.230.0060.00615.69
7.1.220.0060.01015.76
7.1.210.0040.00815.76
7.1.200.0040.00815.98
7.1.190.0110.00415.76
7.1.180.0120.00415.98
7.1.170.0060.01015.84
7.1.160.0070.00715.95
7.1.150.0000.01615.88
7.1.140.0030.01015.94
7.1.130.0090.00615.77
7.1.120.0000.01015.43
7.1.110.0000.01415.58
7.1.100.0090.00517.09
7.1.90.0000.01115.93
7.1.80.0000.01315.89
7.1.70.0090.00216.59
7.1.60.0050.01617.58
7.1.50.0050.01316.48
7.1.40.0040.00415.76
7.1.30.0060.00315.54
7.1.20.0030.01515.88
7.1.10.0030.01415.97
7.1.00.0020.02619.04
7.0.330.0040.01115.45
7.0.320.0000.01415.60
7.0.310.0060.01015.21
7.0.300.0030.00915.33
7.0.290.0000.01515.42
7.0.280.0100.00315.40
7.0.270.0000.01415.48
7.0.260.0090.00315.24
7.0.250.0030.00615.28
7.0.240.0030.00915.46
7.0.230.0110.00015.44
7.0.220.0100.00315.48
7.0.210.0090.00315.50
7.0.200.0020.00816.14
7.0.190.0080.00715.39
7.0.180.0000.00815.52
7.0.170.0000.00915.45
7.0.160.0060.00615.55
7.0.150.0060.01015.40
7.0.140.0050.04218.68
7.0.130.0060.00315.27
7.0.120.0040.01115.43
7.0.110.0090.04717.60
7.0.100.0100.03317.78
7.0.90.0030.05017.65
7.0.80.0060.04317.69
7.0.70.0080.04517.89
7.0.60.0080.04317.86
7.0.50.0070.04717.92
7.0.40.0070.04516.83
7.0.30.0080.04316.76
7.0.20.0080.04216.77
7.0.10.0050.04916.80
7.0.00.0090.03916.76
5.6.400.0030.01214.36
5.6.390.0100.00314.53
5.6.380.0070.01014.23
5.6.370.0000.01514.88
5.6.360.0050.00514.62
5.6.350.0060.00314.38
5.6.340.0000.00914.54
5.6.330.0100.00614.68
5.6.320.0030.01114.52
5.6.310.0000.01214.74
5.6.300.0040.01414.57
5.6.290.0030.01014.75
5.6.280.0050.03817.87
5.6.270.0040.01514.57
5.6.260.0090.00614.36
5.6.250.0030.04517.57
5.6.240.0050.02617.61
5.6.230.0040.05017.52
5.6.220.0060.04317.66
5.6.210.0070.04617.59
5.6.200.0030.04517.87
5.6.190.0050.04717.75
5.6.180.0050.04317.89
5.6.170.0030.04317.70
5.6.160.0070.03017.78
5.6.150.0030.03017.84
5.6.140.0030.02517.70
5.6.130.0030.03017.80
5.6.120.0060.02517.68
5.6.110.0070.03717.98
5.6.100.0060.02518.05
5.6.90.0050.02617.79
5.6.80.0060.03217.49
5.6.70.0100.02017.51
5.6.60.0090.02117.54
5.6.50.0030.02517.49
5.6.40.0050.03317.42
5.6.30.0030.02317.51
5.6.20.0030.02717.57
5.6.10.0030.02717.52
5.6.00.0030.02617.63
5.5.380.0020.04717.28
5.5.370.0070.04517.57
5.5.360.0100.04217.19
5.5.350.0050.04517.63
5.5.340.0060.04517.74
5.5.330.0090.04417.72
5.5.320.0030.03217.77
5.5.310.0050.04317.75
5.5.300.0050.03617.82
5.5.290.0060.02517.68
5.5.280.0060.02517.85
5.5.270.0060.03117.65
5.5.260.0050.02517.47
5.5.250.0050.02517.65
5.5.240.0090.04317.50
5.5.230.0080.04017.28
5.5.220.0050.02117.44
5.5.210.0040.04417.28
5.5.200.0060.03617.27
5.5.190.0030.02417.22
5.5.180.0070.02417.31
5.5.170.0110.00314.43
5.5.160.0040.02417.42
5.5.150.0080.02017.40
5.5.140.0040.02417.48
5.5.130.0050.02517.25
5.5.120.0060.02517.29
5.5.110.0080.03317.46
5.5.100.0050.02317.30
5.5.90.0080.01817.40
5.5.80.0050.02017.31
5.5.70.0050.02317.48
5.5.60.0000.02717.27
5.5.50.0020.03017.31
5.5.40.0060.02117.01
5.5.30.0020.03017.29
5.5.20.0060.04617.17
5.5.10.0000.02717.30
5.5.00.0050.03117.27
5.4.450.0050.03415.47
5.4.440.0080.02315.47
5.4.430.0020.02515.38
5.4.420.0020.02515.27
5.4.410.0020.03015.28
5.4.400.0070.02715.05
5.4.390.0050.01814.93
5.4.380.0070.04115.13
5.4.370.0050.02015.11
5.4.360.0020.02415.11
5.4.350.0050.02015.18
5.4.340.0070.02815.15
5.4.330.0030.00710.91
5.4.320.0030.03515.22
5.4.310.0020.02915.12
5.4.300.0030.02215.23
5.4.290.0080.01815.21
5.4.280.0040.04215.18
5.4.270.0020.02215.13
5.4.260.0010.03315.29
5.4.250.0050.02915.07
5.4.240.0060.02015.30
5.4.230.0020.02615.16
5.4.220.0050.02115.23
5.4.210.0070.01815.12
5.4.200.0020.03515.08
5.4.190.0050.02315.26
5.4.180.0020.02515.15
5.4.170.0050.02215.12
5.4.160.0030.02615.21
5.4.150.0080.03315.11
5.4.140.0060.04113.88
5.4.130.0030.03013.80
5.4.120.0080.01813.78
5.4.110.0070.03913.87
5.4.100.0060.03313.94
5.4.90.0050.04213.82
5.4.80.0090.03313.84
5.4.70.0020.04413.79
5.4.60.0070.03613.89
5.4.50.0050.04213.90
5.4.40.0100.03113.81
5.4.30.0060.03513.83
5.4.20.0080.03313.93
5.4.10.0050.02713.76
5.4.00.0020.04213.52
5.3.290.0080.02012.81
5.3.280.0020.02412.74
5.3.270.0000.02212.69
5.3.260.0090.02312.81
5.3.250.0030.02012.69
5.3.240.0090.02712.67
5.3.230.0030.02412.60
5.3.220.0070.03412.55
5.3.210.0000.02512.71
5.3.200.0040.02412.68
5.3.190.0020.04012.68
5.3.180.0020.04112.81
5.3.170.0030.04012.75
5.3.160.0050.03812.74
5.3.150.0100.04012.68
5.3.140.0050.04012.61
5.3.130.0080.04012.82
5.3.120.0050.04012.68
5.3.110.0110.02012.63
5.3.100.0070.04212.40
5.3.90.0100.02712.46
5.3.80.0110.03212.29
5.3.70.0060.03812.36
5.3.60.0020.04212.29
5.3.50.0050.04212.27
5.3.40.0020.04312.30
5.3.30.0070.03812.31
5.3.20.0050.03512.19
5.3.10.0100.01911.97
5.3.00.0020.04312.01

preferences:
59.39 ms | 400 KiB | 5 Q