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; $jump = -1; $loop = array(); $depth = 0; for ($this->i=0;$this->i<strlen($this->code);$this->i++) { $c = $this->c = substr($this->code, $this->i, 1); $cell = $this->arr[$this->ptr]; if (!in_array($c, $this->commands)) { continue; } else if ($jump >= 0) { if ($c == '[') { $depth++; } if ($c == ']') { if ($depth === $jump) { $jump = -1; $this->stack(); } $depth--; } } else { if ($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 == '[') { if ($cell == 0) { $this->stack('jump'); $jump = $depth; } else { array_push($loop, $this->i); } $depth++; } elseif ($c == ']') { if ($cell > 0) { $this->i = $loop[count($loop)-1]; continue; } else { array_pop($loop); $depth--; continue; } } } } } 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 decrement_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; foreach ($c->getCallStack() as $k => $call) { echo '#'.$k.' '.$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.0060.01318.55
8.3.50.0050.01021.26
8.3.40.0030.01218.96
8.3.30.0070.00720.34
8.3.20.0040.00420.20
8.3.10.0040.00421.79
8.3.00.0000.00820.71
8.2.180.0100.01016.75
8.2.170.0040.01122.96
8.2.160.0080.00520.30
8.2.150.0080.00024.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0040.00419.67
8.2.110.0090.00022.19
8.2.100.0090.00318.16
8.2.90.0050.00318.28
8.2.80.0040.00417.97
8.2.70.0000.01017.75
8.2.60.0030.00618.29
8.2.50.0000.00818.07
8.2.40.0080.00018.41
8.2.30.0030.00918.21
8.2.20.0000.00817.82
8.2.10.0030.00517.84
8.2.00.0040.00417.95
8.1.280.0070.01425.92
8.1.270.0020.00524.66
8.1.260.0000.00926.35
8.1.250.0080.00028.09
8.1.240.0000.00922.50
8.1.230.0080.00321.01
8.1.220.0000.00817.88
8.1.210.0040.00418.97
8.1.200.0000.01017.36
8.1.190.0080.00017.78
8.1.180.0060.00319.00
8.1.170.0000.01118.62
8.1.160.0040.00422.19
8.1.150.0000.00918.66
8.1.140.0040.00417.47
8.1.130.0040.00417.91
8.1.120.0070.00017.60
8.1.110.0000.00717.57
8.1.100.0020.00517.47
8.1.90.0040.00417.53
8.1.80.0000.00717.45
8.1.70.0000.00717.41
8.1.60.0040.00417.65
8.1.50.0030.00517.63
8.1.40.0040.00417.66
8.1.30.0040.00417.70
8.1.20.0040.00417.75
8.1.10.0030.00617.49
8.1.00.0040.00417.55
8.0.300.0000.00820.16
8.0.290.0000.00917.30
8.0.280.0000.00818.57
8.0.270.0030.00317.27
8.0.260.0030.00316.91
8.0.250.0000.00716.94
8.0.240.0040.00416.95
8.0.230.0070.00017.01
8.0.220.0050.00317.01
8.0.210.0030.00316.88
8.0.200.0000.00717.07
8.0.190.0090.00017.02
8.0.180.0000.00717.01
8.0.170.0000.00816.88
8.0.160.0070.00017.00
8.0.150.0000.00716.89
8.0.140.0040.00417.00
8.0.130.0000.00713.48
8.0.120.0040.00416.98
8.0.110.0040.00417.00
8.0.100.0050.00316.91
8.0.90.0040.00416.90
8.0.80.0100.00717.02
8.0.70.0040.00416.83
8.0.60.0040.00417.00
8.0.50.0080.00016.92
8.0.30.0080.01117.18
8.0.20.0140.00517.40
8.0.10.0040.00416.99
8.0.00.0090.01416.79
7.4.330.0000.00515.07
7.4.320.0030.00316.53
7.4.300.0000.00716.55
7.4.290.0050.00316.55
7.4.280.0080.00016.68
7.4.270.0030.00316.73
7.4.260.0080.00316.70
7.4.250.0070.00016.57
7.4.240.0020.00516.53
7.4.230.0030.00316.53
7.4.220.0160.01016.62
7.4.210.0100.00816.65
7.4.200.0040.00416.56
7.4.190.0040.00416.57
7.4.160.0130.00316.75
7.4.150.0140.00417.40
7.4.140.0140.00817.86
7.4.130.0080.00916.65
7.4.120.0090.00916.61
7.4.110.0040.01316.70
7.4.100.0090.00916.64
7.4.90.0100.01316.72
7.4.80.0140.00319.39
7.4.70.0090.00816.66
7.4.60.0040.01516.55
7.4.50.0040.00416.39
7.4.40.0100.00722.77
7.4.30.0120.01216.57
7.4.10.0060.01214.91
7.4.00.0100.00815.21
7.3.330.0050.00013.34
7.3.320.0000.00513.23
7.3.310.0040.00416.43
7.3.300.0050.00316.45
7.3.290.0030.01716.48
7.3.280.0110.00616.45
7.3.270.0100.01017.40
7.3.260.0140.01116.71
7.3.250.0100.00916.47
7.3.240.0160.00716.55
7.3.230.0060.01216.50
7.3.210.0000.01716.48
7.3.200.0140.00319.39
7.3.190.0090.00916.59
7.3.180.0060.01016.48
7.3.170.0160.00016.75
7.3.160.0080.01516.68
7.3.130.0130.00615.00
7.3.120.0050.01414.96
7.3.110.0030.01715.07
7.3.100.0000.00914.95
7.3.90.0000.01114.69
7.3.80.0100.00014.76
7.3.70.0090.00614.89
7.3.60.0030.01015.01
7.3.50.0060.00914.73
7.3.40.0040.01115.02
7.3.30.0040.01415.04
7.3.20.0090.00616.54
7.3.10.0090.00616.61
7.3.00.0030.00716.69
7.2.330.0130.00416.64
7.2.320.0040.01416.88
7.2.310.0130.00316.59
7.2.300.0130.00316.65
7.2.290.0140.00316.47
7.2.260.0100.01015.35
7.2.250.0070.01315.14
7.2.240.0060.00915.31
7.2.230.0000.01715.27
7.2.220.0060.00915.29
7.2.210.0060.01115.17
7.2.200.0060.01315.14
7.2.190.0030.01015.27
7.2.180.0030.01314.96
7.2.170.0060.00615.20
7.2.160.0030.01215.30
7.2.150.0000.01516.92
7.2.140.0000.01216.96
7.2.130.0060.00916.85
7.2.120.0060.00916.97
7.2.110.0070.00717.07
7.2.100.0140.00316.81
7.2.90.0100.00317.02
7.2.80.0070.00316.80
7.2.70.0070.01017.01
7.2.60.0070.00416.95
7.2.50.0000.01116.72
7.2.40.0030.00916.86
7.2.30.0090.00617.11
7.2.20.0070.01016.97
7.2.10.0090.00317.09
7.2.00.0050.01218.11
7.1.330.0030.01015.87
7.1.320.0070.01015.88
7.1.310.0030.01415.92
7.1.300.0030.01015.91
7.1.290.0100.00715.44
7.1.280.0030.01315.78
7.1.270.0030.01315.79
7.1.260.0030.01215.76
7.1.250.0060.01215.83
7.1.240.0000.01315.75
7.1.230.0120.00315.99
7.1.220.0070.01015.69
7.1.210.0070.01115.92
7.1.200.0060.00615.89
7.1.190.0040.00815.80
7.1.180.0060.00915.70
7.1.170.0090.00616.04
7.1.160.0090.00615.88
7.1.150.0000.00915.99
7.1.140.0070.00715.58
7.1.130.0030.01015.64
7.1.120.0040.01115.94
7.1.110.0080.00615.93
7.1.100.0040.00716.98
7.1.90.0090.00615.93
7.1.80.0000.01315.66
7.1.70.0060.00616.51
7.1.60.0050.01517.56
7.1.50.0070.00516.43
7.1.40.0090.00615.78
7.1.30.0000.01115.58
7.1.20.0110.00415.88
7.1.10.0070.01015.79
7.1.00.0020.02419.15
7.0.330.0120.00615.27
7.0.320.0040.01415.56
7.0.310.0000.01315.43
7.0.300.0030.00915.46
7.0.290.0040.01215.47
7.0.280.0090.00615.56
7.0.270.0060.00315.26
7.0.260.0030.01215.21
7.0.250.0040.00815.40
7.0.240.0040.00715.34
7.0.230.0040.01115.10
7.0.220.0080.00515.53
7.0.210.0030.01015.11
7.0.200.0250.00515.39
7.0.190.0120.00315.63
7.0.180.0110.00415.47
7.0.170.0000.00915.35
7.0.160.0030.01015.36
7.0.150.0000.01815.28
7.0.140.0010.04418.60
7.0.130.0000.00815.52
7.0.120.0060.01215.54
7.0.110.0060.01115.57
7.0.100.0060.03517.86
7.0.90.0070.03117.67
7.0.80.0070.04217.86
7.0.70.0060.04117.75
7.0.60.0070.04718.03
7.0.50.0080.04718.13
7.0.40.0050.04817.09
7.0.30.0060.04617.01
7.0.20.0130.04117.13
7.0.10.0050.03017.18
7.0.00.0080.03516.98
5.6.400.0030.01614.20
5.6.390.0030.01514.47
5.6.380.0040.01114.54
5.6.370.0000.01814.64
5.6.360.0030.00614.45
5.6.350.0000.01614.77
5.6.340.0040.00714.62
5.6.330.0030.00914.76
5.6.320.0060.00314.58
5.6.310.0000.01714.54
5.6.300.0070.00714.83
5.6.290.0040.00814.68
5.6.280.0070.03917.72
5.6.270.0030.01314.59
5.6.260.0130.00614.28
5.6.250.0080.04517.67
5.6.240.0070.04117.65
5.6.230.0060.03317.58
5.6.220.0090.02817.72
5.6.210.0090.03917.56
5.6.200.0020.03017.79
5.6.190.0070.04517.83
5.6.180.0070.04717.90
5.6.170.0100.04517.83
5.6.160.0050.04217.75
5.6.150.0060.03617.77
5.6.140.0070.02818.04
5.6.130.0100.03217.77
5.6.120.0070.04317.79
5.6.110.0050.03917.95
5.6.100.0090.03117.81
5.6.90.0100.04517.87
5.6.80.0070.02517.41
5.6.70.0080.02417.55
5.6.60.0090.05417.63
5.6.50.0020.04617.58
5.6.40.0080.03517.29
5.6.30.0080.04617.64
5.6.20.0080.04717.38
5.6.10.0150.01817.37
5.6.00.0080.03617.32
5.5.380.0050.04317.48
5.5.370.0090.03717.42
5.5.360.0110.04117.35
5.5.350.0090.04017.33
5.5.340.0050.05017.67
5.5.330.0050.02917.83
5.5.320.0020.04817.77
5.5.310.0080.02517.78
5.5.300.0070.03117.59
5.5.290.0060.02617.67
5.5.280.0030.02617.80
5.5.270.0050.03917.72
5.5.260.0090.02917.81
5.5.250.0110.04017.62
5.5.240.0050.03717.35
5.5.230.0050.04117.25
5.5.220.0070.04017.26
5.5.210.0090.03317.36
5.5.200.0060.04517.33
5.5.190.0120.03817.38
5.5.180.0100.04017.26
5.5.170.0040.01114.60
5.5.160.0020.03817.41
5.5.150.0050.03817.24
5.5.140.0070.04117.39
5.5.130.0100.04017.39
5.5.120.0080.03117.39
5.5.110.0060.04017.38
5.5.100.0120.02517.39
5.5.90.0100.04317.36
5.5.80.0120.04017.16
5.5.70.0050.04717.31
5.5.60.0070.02717.23
5.5.50.0050.04017.35
5.5.40.0050.04317.19
5.5.30.0100.02317.39
5.5.20.0080.02617.26
5.5.10.0060.02517.20
5.5.00.0050.04517.38
5.4.450.0080.04315.29
5.4.440.0070.03015.50
5.4.430.0100.04015.31
5.4.420.0070.04015.50
5.4.410.0070.04115.14
5.4.400.0070.02515.16
5.4.390.0050.02415.16
5.4.380.0030.03015.10
5.4.370.0030.04315.05
5.4.360.0060.03915.17
5.4.350.0050.04615.08
5.4.340.0050.03015.06
5.4.330.0070.00711.31
5.4.320.0060.02815.13
5.4.310.0080.03615.04
5.4.300.0030.02915.30
5.4.290.0120.03315.15
5.4.280.0050.03615.16
5.4.270.0020.02615.08
5.4.260.0030.04515.04
5.4.250.0030.04114.98
5.4.240.0100.03515.08
5.4.230.0110.03315.23
5.4.220.0060.02915.28
5.4.210.0070.03215.04
5.4.200.0050.04215.24
5.4.190.0110.03715.19
5.4.180.0060.04115.07
5.4.170.0110.04015.20
5.4.160.0110.02215.20
5.4.150.0120.02515.13
5.4.140.0030.03613.94
5.4.130.0070.04414.00
5.4.120.0030.04013.72
5.4.110.0050.04113.89
5.4.100.0050.04313.90
5.4.90.0040.03213.80
5.4.80.0070.03913.87
5.4.70.0070.02513.68
5.4.60.0070.03713.92
5.4.50.0050.03813.96
5.4.40.0060.03613.93
5.4.30.0090.03713.77
5.4.20.0020.04313.87
5.4.10.0090.03313.88
5.4.00.0080.02513.59
5.3.290.0020.04512.71
5.3.280.0060.03612.55
5.3.270.0030.02212.81
5.3.260.0040.04012.77
5.3.250.0080.03912.71
5.3.240.0100.04012.50
5.3.230.0020.02812.63
5.3.220.0080.04012.64
5.3.210.0050.03812.72
5.3.200.0080.03712.61
5.3.190.0070.03912.65
5.3.180.0030.04412.71
5.3.170.0120.02012.79
5.3.160.0070.03612.67
5.3.150.0050.02312.70
5.3.140.0070.03912.63
5.3.130.0000.03112.66
5.3.120.0060.04112.69
5.3.110.0000.04912.59
5.3.100.0030.04512.42
5.3.90.0030.02712.43
5.3.80.0030.02712.38
5.3.70.0040.03912.38
5.3.60.0070.04312.35
5.3.50.0060.04012.40
5.3.40.0030.03212.27
5.3.30.0000.02412.33
5.3.20.0070.03412.05
5.3.10.0050.03912.04
5.3.00.0100.03812.01

preferences:
46.76 ms | 401 KiB | 5 Q