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) { 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; } 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.0090.01218.56
8.3.50.0140.00016.36
8.3.40.0120.00318.90
8.3.30.0070.00720.23
8.3.20.0040.00420.19
8.3.10.0000.00721.92
8.3.00.0080.00020.67
8.2.180.0150.00616.75
8.2.170.0110.00722.96
8.2.160.0070.00720.39
8.2.150.0040.00424.18
8.2.140.0100.01024.66
8.2.130.0040.00426.16
8.2.120.0030.00619.66
8.2.110.0090.00020.47
8.2.100.0040.00817.84
8.2.90.0040.00419.12
8.2.80.0030.00619.28
8.2.70.0060.00317.75
8.2.60.0080.00018.05
8.2.50.0000.00818.07
8.2.40.0040.00418.09
8.2.30.0070.00318.24
8.2.20.0040.00417.87
8.2.10.0000.00817.90
8.2.00.0060.00617.93
8.1.270.0040.00424.66
8.1.260.0030.00626.35
8.1.250.0040.00428.09
8.1.240.0030.00624.02
8.1.230.0070.00419.22
8.1.220.0040.00417.74
8.1.210.0060.00318.77
8.1.200.0050.00517.59
8.1.190.0080.00017.78
8.1.180.0050.00319.01
8.1.170.0100.00018.72
8.1.160.0040.00422.19
8.1.150.0030.00618.79
8.1.140.0000.00717.57
8.1.130.0030.00317.80
8.1.120.0000.00717.53
8.1.110.0040.00417.41
8.1.100.0070.00017.54
8.1.90.0050.00317.54
8.1.80.0070.00017.54
8.1.70.0030.00317.54
8.1.60.0030.00517.60
8.1.50.0080.00017.54
8.1.40.0040.00417.61
8.1.30.0040.00417.69
8.1.20.0060.00317.73
8.1.10.0000.00817.69
8.1.00.0060.00617.42
8.0.300.0080.00018.77
8.0.290.0000.00717.18
8.0.280.0030.00318.46
8.0.270.0000.00717.39
8.0.260.0000.00716.85
8.0.250.0030.00316.98
8.0.240.0080.00017.09
8.0.230.0000.00816.93
8.0.220.0030.00317.00
8.0.210.0080.00017.03
8.0.200.0030.00317.13
8.0.190.0000.00816.99
8.0.180.0060.00317.04
8.0.170.0040.00416.94
8.0.160.0040.00416.99
8.0.150.0040.00416.99
8.0.140.0070.00016.96
8.0.130.0070.00013.51
8.0.120.0050.00316.87
8.0.110.0000.00716.92
8.0.100.0000.00717.05
8.0.90.0040.00416.91
8.0.80.0030.01216.98
8.0.70.0030.00517.08
8.0.60.0040.00417.14
8.0.50.0040.00417.13
8.0.30.0120.00817.24
8.0.20.0080.01317.43
8.0.10.0040.00416.96
8.0.00.0150.00716.80
7.4.330.0050.00215.00
7.4.320.0030.00316.55
7.4.300.0000.00616.62
7.4.290.0070.00016.65
7.4.280.0000.00716.57
7.4.270.0070.00016.58
7.4.260.0000.00816.65
7.4.250.0060.00316.53
7.4.240.0000.00716.51
7.4.230.0000.00716.41
7.4.220.0150.00716.66
7.4.210.0050.01116.58
7.4.200.0080.00016.70
7.4.190.0000.00716.61
7.4.160.0070.01016.46
7.4.150.0130.00717.40
7.4.140.0110.00617.86
7.4.130.0030.01416.57
7.4.120.0100.01116.61
7.4.110.0180.00016.67
7.4.100.0110.00716.62
7.4.90.0080.01116.48
7.4.80.0090.00919.39
7.4.70.0080.01216.60
7.4.60.0080.00816.48
7.4.50.0050.00016.57
7.4.40.0120.00322.77
7.4.30.0130.00616.60
7.4.00.0110.00515.09
7.3.330.0000.00613.23
7.3.320.0060.00013.54
7.3.310.0070.00016.47
7.3.300.0000.00716.45
7.3.290.0090.00616.38
7.3.280.0070.01116.45
7.3.270.0100.00717.40
7.3.260.0060.01316.60
7.3.250.0050.01216.55
7.3.240.0040.01416.62
7.3.230.0030.01516.63
7.3.210.0130.00316.50
7.3.200.0090.01319.39
7.3.190.0100.01016.59
7.3.180.0170.00316.74
7.3.170.0100.00616.53
7.3.160.0110.00716.43
7.3.120.0060.01115.08
7.3.110.0090.00614.82
7.3.100.0050.00914.93
7.3.90.0060.00615.01
7.3.80.0020.00915.07
7.3.70.0040.00814.86
7.3.60.0050.00614.89
7.3.50.0060.00614.84
7.3.40.0080.00614.96
7.3.30.0080.00814.76
7.3.20.0040.01116.49
7.3.10.0050.00816.54
7.3.00.0050.01016.71
7.2.330.0090.00916.78
7.2.320.0080.01216.85
7.2.310.0030.01416.72
7.2.300.0070.01316.77
7.2.290.0070.01016.58
7.2.250.0070.01214.97
7.2.240.0090.00815.23
7.2.230.0060.00815.16
7.2.220.0050.00815.19
7.2.210.0060.00815.21
7.2.200.0070.00715.20
7.2.190.0050.01115.20
7.2.180.0060.00515.35
7.2.170.0020.01015.07
7.2.60.0060.01016.64
7.2.00.0030.01219.05
7.1.330.0090.00515.93
7.1.320.0070.00715.95
7.1.310.0050.00715.86
7.1.300.0060.00915.67
7.1.290.0020.01315.68
7.1.280.0020.01215.71
7.1.270.0060.00915.85
7.1.260.0030.01215.73
7.1.200.0000.01115.96
7.1.100.0000.01518.02
7.1.70.0060.00617.36
7.1.60.0090.01619.21
7.1.50.0130.00916.69
7.1.00.0100.03022.31
7.0.200.0430.00314.86
7.0.140.0030.07322.00
7.0.60.0130.05720.15
7.0.50.0100.05717.77
7.0.40.0030.04320.21
7.0.30.0200.07720.06
7.0.20.0200.04720.23
7.0.10.0030.04320.23
7.0.00.0100.08320.08
5.6.280.0030.07321.18
5.6.210.0030.04020.52
5.6.200.0030.08018.18
5.6.190.0030.04320.47
5.6.180.0230.07320.47
5.6.170.0330.05320.52
5.6.160.0070.04020.55
5.6.150.0100.04718.26
5.6.140.0030.04018.17
5.6.130.0070.04018.26
5.6.120.0030.04321.18
5.6.110.0000.04721.15
5.6.100.0100.08021.04
5.6.90.0100.07721.01
5.6.80.0070.08020.52
5.5.350.0030.03020.48
5.5.340.0000.04317.98
5.5.330.0070.04320.41
5.5.320.0000.08720.31
5.5.310.0300.04720.13
5.5.300.0100.07717.98
5.5.290.0100.06318.08
5.5.280.0030.04020.80
5.5.270.0100.08020.68
5.5.260.0100.07320.83
5.5.250.0070.05320.82
5.5.240.0130.04020.16
5.4.450.0700.05019.54
5.4.440.0570.03319.55
5.4.430.0600.04319.48
5.4.420.0900.04719.21
5.4.410.0630.04319.34
5.4.400.0600.04019.07
5.4.390.0130.04718.87
5.4.380.0530.06718.56
5.4.370.0330.06018.50
5.4.360.0400.05718.54
5.4.350.0330.05318.51
5.4.340.0430.05318.50
5.4.320.0040.04112.54
5.4.310.0020.04112.53
5.4.300.0080.04112.54
5.4.290.0070.03612.54
5.4.280.0030.05012.43
5.4.270.0070.04412.43
5.4.260.0080.04512.43
5.4.250.0100.05318.97
5.4.240.0130.07718.84
5.4.230.0200.05019.04
5.4.220.0070.05318.94
5.4.210.0130.04719.09
5.4.200.0100.05719.00
5.4.190.0070.05718.90
5.4.180.0100.06318.95
5.4.170.0130.05018.61
5.4.160.0130.05018.89
5.4.150.0170.04319.09
5.4.140.0100.06716.59
5.4.130.0100.05016.44
5.4.120.0100.06316.58
5.4.110.0070.05016.57
5.4.100.0000.05716.56
5.4.90.0070.05016.41
5.4.80.0100.05016.56
5.4.70.0200.06716.56
5.4.60.0070.07316.34
5.4.50.0100.05316.34
5.4.40.0030.05316.69
5.4.30.0000.06316.50
5.4.20.0130.04316.57
5.4.10.0030.07316.50
5.4.00.0130.06315.84
5.3.290.0060.04912.80
5.3.280.0130.05014.54
5.3.270.0100.05014.74
5.3.260.0130.04714.50
5.3.250.0070.05314.73
5.3.240.0170.04014.71
5.3.230.0130.04714.63
5.3.220.0030.05714.64
5.3.210.0070.05314.51
5.3.200.0070.05014.83
5.3.190.0200.05314.60
5.3.180.0030.05314.51
5.3.170.0000.05314.77
5.3.160.0070.06014.79
5.3.150.0170.04014.69
5.3.140.0100.05314.68
5.3.130.0130.06714.77
5.3.120.0130.06714.56
5.3.110.0170.04314.68
5.3.100.0100.05014.24
5.3.90.0100.04314.14
5.3.80.0030.05014.29
5.3.70.0030.05314.04
5.3.60.0000.05714.06
5.3.50.0130.04313.98
5.3.40.0070.05014.18
5.3.30.0070.05014.04
5.3.20.0030.05013.82
5.3.10.0070.05313.68
5.3.00.0100.04713.91
5.2.170.0130.04011.27
5.2.160.0070.04011.28
5.2.150.0030.06711.03
5.2.140.0000.04711.37
5.2.130.0070.03711.22
5.2.120.0070.03711.16
5.2.110.0070.05011.38
5.2.100.0100.05011.24
5.2.90.0070.03711.15
5.2.80.0070.04011.21
5.2.70.0030.04311.15
5.2.60.0070.04011.07
5.2.50.0030.05311.05
5.2.40.0070.03710.96
5.2.30.0100.05011.00
5.2.20.0200.04310.91
5.2.10.0070.03710.99
5.2.00.0070.04710.77
5.1.60.0000.03710.12
5.1.50.0070.03710.00
5.1.40.0070.03310.09
5.1.30.0030.03710.38
5.1.20.0100.03310.57
5.1.10.0170.03710.04
5.1.00.0070.03310.22
5.0.50.0030.0278.69
5.0.40.0100.0208.66
5.0.30.0030.0408.24
5.0.20.0070.0238.33
5.0.10.0070.0308.27
5.0.00.0070.0378.31
4.4.90.0000.0337.42
4.4.80.0030.0207.42
4.4.70.0030.0237.42
4.4.60.0030.0277.42
4.4.50.0030.0237.42
4.4.40.0000.0377.42
4.4.30.0000.0237.42
4.4.20.0000.0237.42
4.4.10.0070.0177.42
4.4.00.0000.0377.42
4.3.110.0030.0307.42
4.3.100.0070.0277.42
4.3.90.0100.0137.42
4.3.80.0070.0407.42
4.3.70.0030.0207.42
4.3.60.0030.0207.42
4.3.50.0000.0237.42
4.3.40.0030.0307.42
4.3.30.0000.0207.42
4.3.20.0000.0237.42
4.3.10.0000.0207.42
4.3.00.0030.01714.48

preferences:
48 ms | 400 KiB | 5 Q