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(); const 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(); $this->ptr = 0; $this->code = $code; for ($this->i=0;$this->i<strlen($this->code);$this->i++) { $c = $this->c = substr($this->code, $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; } } 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)
5.4.250.0200.04318.93
5.4.240.0070.05318.98
5.4.230.0130.04718.93
5.4.220.0070.05718.77
5.4.210.0200.04018.93
5.4.200.0100.05318.93
5.4.190.0170.06318.78
5.4.180.0270.05019.03
5.4.170.0130.04718.73
5.4.160.0100.06018.92
5.4.150.0130.05718.94
5.4.140.0070.05316.37
5.4.130.0070.05316.59
5.4.120.0100.05016.41
5.4.110.0070.05016.43
5.4.100.0130.04316.45
5.4.90.0100.05016.76
5.4.80.0100.05316.60
5.4.70.0070.07016.58
5.4.60.0100.04716.32
5.4.50.0100.05316.62
5.4.40.0230.03316.32
5.4.30.0070.04716.45
5.4.20.0170.04016.44
5.4.10.0030.07316.48
5.4.00.0130.04316.02
5.3.280.0130.05014.69
5.3.270.0130.04314.73
5.3.260.0100.06714.86
5.3.250.0130.04714.63
5.3.240.0200.04014.54
5.3.230.0100.06314.73
5.3.220.0070.05014.69
5.3.210.0100.05014.61
5.3.200.0070.05014.76
5.3.190.0170.06314.61
5.3.180.0130.04714.60
5.3.170.0100.05314.76
5.3.160.0030.05714.58
5.3.150.0100.04714.57
5.3.140.0070.04714.66
5.3.130.0130.06714.59
5.3.120.0100.05014.57
5.3.110.0130.06314.57
5.3.100.0130.04314.20
5.3.90.0100.07014.11
5.3.80.0200.03713.88
5.3.70.0170.06014.14
5.3.60.0100.05014.00
5.3.50.0000.05314.07
5.3.40.0100.04314.06
5.3.30.0100.04314.16
5.3.20.0000.05313.91
5.3.10.0100.06713.65
5.3.00.0170.05313.74

preferences:
140.94 ms | 1394 KiB | 7 Q