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.0160.00618.56
8.3.50.0110.00921.14
8.3.40.0110.01118.84
8.3.30.0100.00320.34
8.3.20.0040.00420.39
8.3.10.0040.00422.09
8.3.00.0080.00020.69
8.2.180.0160.00316.63
8.2.170.0150.00622.96
8.2.160.0030.01020.47
8.2.150.0080.00024.18
8.2.140.0120.00824.66
8.2.130.0000.00826.16
8.2.120.0050.00519.61
8.2.110.0090.00019.39
8.2.100.0080.00417.88
8.2.90.0000.00819.25
8.2.80.0080.00017.97
8.2.70.0040.00417.75
8.2.60.0080.00018.15
8.2.50.0080.00018.07
8.2.40.0030.00619.88
8.2.30.0040.00418.20
8.2.20.0050.00317.79
8.2.10.0070.00017.93
8.2.00.0030.00917.86
8.1.280.0140.00725.92
8.1.270.0040.00424.66
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0000.01123.83
8.1.230.0040.00717.91
8.1.220.0090.00017.91
8.1.210.0040.00418.77
8.1.200.0060.00317.48
8.1.190.0050.00317.35
8.1.180.0000.00818.10
8.1.170.0040.00718.51
8.1.160.0000.00722.06
8.1.150.0030.00618.71
8.1.140.0040.00417.47
8.1.130.0000.00717.97
8.1.120.0050.00317.45
8.1.110.0040.00417.40
8.1.100.0050.00317.46
8.1.90.0020.00517.60
8.1.80.0050.00217.54
8.1.70.0030.00317.44
8.1.60.0060.00317.65
8.1.50.0030.00517.60
8.1.40.0030.00617.64
8.1.30.0040.00417.76
8.1.20.0060.00317.74
8.1.10.0090.00017.64
8.1.00.0040.00717.51
8.0.300.0030.00618.77
8.0.290.0030.00616.88
8.0.280.0000.00718.44
8.0.270.0030.00617.33
8.0.260.0030.00316.96
8.0.250.0040.00417.05
8.0.240.0000.00817.07
8.0.230.0080.00016.91
8.0.220.0000.00717.00
8.0.210.0040.00416.96
8.0.200.0030.00316.95
8.0.190.0000.00717.05
8.0.180.0040.00717.05
8.0.170.0000.00717.05
8.0.160.0000.00717.02
8.0.150.0040.00416.91
8.0.140.0040.00416.78
8.0.130.0030.00313.37
8.0.120.0000.00816.87
8.0.110.0040.00416.88
8.0.100.0040.00416.98
8.0.90.0000.00716.86
8.0.80.0130.00416.91
8.0.70.0040.00416.97
8.0.60.0040.00416.94
8.0.50.0050.00217.01
8.0.30.0110.00817.19
8.0.20.0090.01117.40
8.0.10.0040.00416.94
8.0.00.0060.01116.87
7.4.330.0070.00015.00
7.4.320.0060.00016.72
7.4.300.0060.00016.68
7.4.290.0000.00816.60
7.4.280.0040.00416.67
7.4.270.0030.00416.70
7.4.260.0040.00416.55
7.4.250.0000.00816.54
7.4.240.0030.00516.62
7.4.230.0000.00716.48
7.4.220.0130.00616.71
7.4.210.0070.00916.75
7.4.200.0030.00416.39
7.4.190.0070.00016.73
7.4.160.0090.00916.72
7.4.150.0120.00817.40
7.4.140.0070.01117.86
7.4.130.0070.01116.52
7.4.120.0130.00616.61
7.4.110.0000.01816.58
7.4.100.0180.00016.61
7.4.90.0030.01516.62
7.4.80.0030.01619.39
7.4.70.0060.01216.48
7.4.60.0110.00716.69
7.4.50.0050.00016.65
7.4.40.0030.01022.77
7.4.30.0160.00316.70
7.4.10.0070.01115.15
7.4.00.0040.01115.13
7.3.330.0030.00313.46
7.3.320.0030.00313.41
7.3.310.0060.00316.36
7.3.300.0030.00316.37
7.3.290.0110.00316.51
7.3.280.0050.01316.47
7.3.270.0030.01417.40
7.3.260.0030.01616.74
7.3.250.0120.01116.52
7.3.240.0030.01416.34
7.3.230.0060.01116.39
7.3.210.0130.00316.57
7.3.200.0060.01019.39
7.3.190.0150.00316.60
7.3.180.0060.00916.33
7.3.170.0070.01016.37
7.3.160.0050.01116.45
7.3.130.0090.00914.91
7.3.120.0100.00814.93
7.3.110.0090.00615.12
7.3.100.0060.01015.00
7.3.90.0060.00914.90
7.3.80.0050.00515.00
7.3.70.0100.00614.82
7.3.60.0040.00715.00
7.3.50.0100.00715.01
7.3.40.0090.00314.74
7.3.30.0070.00714.85
7.3.20.0070.00716.72
7.3.10.0040.00816.84
7.3.00.0030.00716.69
7.2.330.0110.00716.39
7.2.320.0100.01016.77
7.2.310.0030.01316.73
7.2.300.0060.01216.52
7.2.290.0170.00016.80
7.2.260.0090.00915.13
7.2.250.0120.00915.37
7.2.240.0030.00915.15
7.2.230.0080.00815.20
7.2.220.0000.01514.98
7.2.210.0030.01214.90
7.2.200.0120.00315.12
7.2.190.0100.00715.23
7.2.180.0030.00915.13
7.2.170.0040.01115.00
7.2.160.0030.01615.09
7.2.150.0030.01017.03
7.2.140.0030.00717.00
7.2.130.0040.01416.88
7.2.120.0040.00816.91
7.2.110.0000.01216.94
7.2.100.0070.00716.89
7.2.90.0100.00616.93
7.2.80.0080.00317.00
7.2.70.0060.00616.83
7.2.60.0060.00316.98
7.2.50.0070.00316.79
7.2.40.0070.01017.04
7.2.30.0070.01016.75
7.2.20.0110.00317.00
7.2.10.0030.01016.95
7.2.00.0030.01218.03
7.1.330.0030.00915.54
7.1.320.0090.00315.66
7.1.310.0030.00715.84
7.1.300.0100.00315.80
7.1.290.0060.00615.94
7.1.280.0060.00915.86
7.1.270.0040.01416.05
7.1.260.0000.01215.69
7.1.250.0070.00715.68
7.1.240.0060.00615.91
7.1.230.0030.00915.84
7.1.220.0060.00615.82
7.1.210.0060.00915.66
7.1.200.0070.00316.02
7.1.190.0090.00315.91
7.1.180.0040.00715.96
7.1.170.0040.00715.73
7.1.160.0070.00716.04
7.1.150.0000.01315.86
7.1.140.0030.01015.53
7.1.130.0040.01115.71
7.1.120.0070.00715.87
7.1.110.0040.00815.75
7.1.100.0050.00616.78
7.1.90.0060.01216.04
7.1.80.0110.00315.81
7.1.70.0030.00816.69
7.1.60.0120.00717.54
7.1.50.0090.00716.30
7.1.40.0070.00715.70
7.1.30.0100.00915.68
7.1.20.0080.00515.79
7.1.10.0080.00315.50
7.1.00.0090.02518.99
7.0.330.0070.00715.55
7.0.320.0120.00315.19
7.0.310.0030.01315.41
7.0.300.0030.00715.39
7.0.290.0090.00615.35
7.0.280.0070.00315.21
7.0.270.0030.00715.43
7.0.260.0030.01415.49
7.0.250.0030.00915.36
7.0.240.0000.01715.36
7.0.230.0000.01415.52
7.0.220.0050.00515.41
7.0.210.0080.00415.21
7.0.200.0120.00815.39
7.0.190.0030.01015.48
7.0.180.0060.00915.27
7.0.170.0030.01315.52
7.0.160.0130.01015.36
7.0.150.0100.00715.45
7.0.140.0000.04718.77
7.0.130.0030.00715.50
7.0.120.0060.00615.45
7.0.110.0060.00915.52
7.0.100.0250.03817.80
7.0.90.0180.03817.75
7.0.80.0100.03817.62
7.0.70.0150.03817.58
7.0.60.0050.02417.97
7.0.50.0080.03218.21
7.0.40.0050.02317.14
7.0.30.0010.02917.20
7.0.20.0070.04217.05
7.0.10.0060.02317.07
7.0.00.0060.02617.12
5.6.400.0090.00614.49
5.6.390.0060.00914.66
5.6.380.0000.01014.37
5.6.370.0090.00614.34
5.6.360.0030.00914.74
5.6.350.0040.01114.71
5.6.340.0100.00014.43
5.6.330.0040.00714.41
5.6.320.0030.00714.77
5.6.310.0040.00814.50
5.6.300.0040.01114.53
5.6.290.0150.00014.42
5.6.280.0030.03917.79
5.6.270.0120.00314.79
5.6.260.0000.01514.56
5.6.250.0050.04717.50
5.6.240.0070.04817.60
5.6.230.0050.04417.53
5.6.220.0120.03817.49
5.6.210.0080.02717.66
5.6.200.0120.02317.95
5.6.190.0100.02117.86
5.6.180.0080.02417.83
5.6.170.0080.02217.90
5.6.160.0040.02617.93
5.6.150.0080.02317.75
5.6.140.0030.02817.78
5.6.130.0050.02517.79
5.6.120.0050.02617.81
5.6.110.0020.02917.89
5.6.100.0080.02317.72
5.6.90.0060.02117.79
5.6.80.0060.02317.61
5.6.70.0070.02017.32
5.6.60.0050.02217.48
5.6.50.0050.02517.51
5.6.40.0130.02017.44
5.6.30.0050.02417.55
5.6.20.0050.02417.52
5.6.10.0030.02617.48
5.6.00.0020.02517.53
5.5.380.0030.04717.43
5.5.370.0080.04017.34
5.5.360.0050.04617.20
5.5.350.0020.03317.30
5.5.340.0030.02617.63
5.5.330.0050.02717.68
5.5.320.0100.03317.65
5.5.310.0050.02317.60
5.5.300.0080.02117.73
5.5.290.0030.03217.63
5.5.280.0080.02317.59
5.5.270.0020.02917.60
5.5.260.0070.02217.78
5.5.250.0050.02717.55
5.5.240.0100.02217.19
5.5.230.0120.02017.45
5.5.220.0050.04617.04
5.5.210.0060.02817.31
5.5.200.0120.02217.17
5.5.190.0070.02017.35
5.5.180.0020.03217.27
5.5.170.0060.00614.26
5.5.160.0060.02117.48
5.5.150.0100.02117.26
5.5.140.0120.02217.40
5.5.130.0030.03417.22
5.5.120.0030.02517.27
5.5.110.0070.02517.29
5.5.100.0070.04217.19
5.5.90.0070.04117.18
5.5.80.0100.03117.16
5.5.70.0050.03017.18
5.5.60.0110.04117.32
5.5.50.0090.04217.15
5.5.40.0080.03717.21
5.5.30.0140.02117.29
5.5.20.0080.03817.22
5.5.10.0050.03517.23
5.5.00.0030.03217.09
5.4.450.0020.02715.20
5.4.440.0050.02615.41
5.4.430.0030.02515.28
5.4.420.0030.02415.15
5.4.410.0030.02715.25
5.4.400.0030.03015.13
5.4.390.0040.02615.00
5.4.380.0090.01715.12
5.4.370.0020.02015.24
5.4.360.0050.02115.04
5.4.350.0030.02515.22
5.4.340.0080.02015.24
5.4.330.0000.00711.28
5.4.320.0030.02515.26
5.4.310.0050.02315.00
5.4.300.0050.02115.01
5.4.290.0090.02015.19
5.4.280.0090.02015.23
5.4.270.0020.02515.21
5.4.260.0050.04315.05
5.4.250.0050.02315.00
5.4.240.0030.02415.14
5.4.230.0040.02115.08
5.4.220.0090.03914.85
5.4.210.0060.04214.92
5.4.200.0060.03314.99
5.4.190.0060.04115.28
5.4.180.0050.03115.15
5.4.170.0040.04315.22
5.4.160.0030.02215.02
5.4.150.0030.04315.09
5.4.140.0060.04313.74
5.4.130.0050.03813.76
5.4.120.0050.03713.77
5.4.110.0060.02313.84
5.4.100.0080.03113.82
5.4.90.0090.03613.69
5.4.80.0050.03813.86
5.4.70.0060.04013.69
5.4.60.0070.03513.86
5.4.50.0050.03913.81
5.4.40.0080.03913.68
5.4.30.0110.03813.86
5.4.20.0100.03613.67
5.4.10.0080.03713.89
5.4.00.0080.04013.52
5.3.290.0050.03412.80
5.3.280.0050.04012.76
5.3.270.0040.02112.76
5.3.260.0020.03912.76
5.3.250.0120.03612.76
5.3.240.0050.04212.51
5.3.230.0030.04212.57
5.3.220.0070.03712.64
5.3.210.0050.04212.72
5.3.200.0100.02012.60
5.3.190.0000.04512.71
5.3.180.0070.03012.75
5.3.170.0030.04512.72
5.3.160.0060.02512.79
5.3.150.0050.04212.77
5.3.140.0050.03912.65
5.3.130.0100.03812.67
5.3.120.0050.04212.72
5.3.110.0130.03812.66
5.3.100.0050.04112.40
5.3.90.0070.04212.44
5.3.80.0080.02512.31
5.3.70.0030.04412.39
5.3.60.0030.02612.24
5.3.50.0020.02712.34
5.3.40.0080.03812.36
5.3.30.0110.03512.35
5.3.20.0050.04112.04
5.3.10.0060.03911.96
5.3.00.0030.04212.14

preferences:
40.76 ms | 401 KiB | 5 Q