3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ExpressionCalculator { private $operators = array( function ($leftOperand, $rightOperand) { return $leftOperand + $rightOperand; }, function ($leftOperand, $rightOperand) { return $leftOperand - $rightOperand; }, function ($leftOperand, $rightOperand) { return $leftOperand * $rightOperand; }, function ($leftOperand, $rightOperand) { return $leftOperand / $rightOperand; } ); public function calc($expression) { $operands = array(); while (($token = strtok($expression, ' ')) !== false) { if (isOperator($token)) { $rightOperand = array_pop($operands); $leftOperand = array_pop($operands); $result = $this->execute($token, $leftOperand, $rightOperand); array_push($operands, $result); } else if (is_numeric($token)) { array_push($operands, $token); } else { throw new InvalidArgumentException('Expression has invalid token: ' + $token); } } return $result; } private function isOperator($token) { return isset($operators[$token]); } private function execute($operator, $leftOperand, $rightOperand) { return call_user_func($operators[$operator], $leftOperand, $rightOperand); } } $calc = new ExpressionCalculator(); echo $calc->calc('5 1 2 + 4 * + 3 -'); // 14

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.240.0090.04212.39
5.4.230.0080.03712.38
5.4.220.0070.03612.38
5.4.210.0110.03912.38
5.4.200.0050.04512.38
5.4.190.0090.03912.38
5.4.180.0050.04412.38
5.4.170.0080.04112.38
5.4.160.0060.03812.38
5.4.150.0050.03912.37
5.4.140.0060.04312.07
5.4.130.0080.03612.04
5.4.120.0110.04212.01
5.4.110.0080.04112.01
5.4.100.0070.03512.01
5.4.90.0060.04312.01
5.4.80.0040.04212.01
5.4.70.0050.04212.00
5.4.60.0060.03912.00
5.4.50.0050.04212.00
5.4.40.0070.03811.99
5.4.30.0080.03811.99
5.4.20.0070.04611.98
5.4.10.0050.03711.99
5.4.00.0080.03711.48
5.3.280.0090.03712.71
5.3.270.0070.03812.72
5.3.260.0070.04212.71
5.3.250.0080.03912.72
5.3.240.0070.04712.72
5.3.230.0090.04112.71
5.3.220.0070.04112.68
5.3.210.0090.03712.68
5.3.200.0050.04612.68
5.3.190.0070.04612.68
5.3.180.0080.04212.67
5.3.170.0070.04012.67
5.3.160.0090.04112.67
5.3.150.0040.04112.68
5.3.140.0060.03812.66
5.3.130.0070.03912.66
5.3.120.0040.04312.66
5.3.110.0050.04312.66
5.3.100.0070.03612.12
5.3.90.0080.03612.09
5.3.80.0040.03912.08
5.3.70.0100.03712.08
5.3.60.0110.03912.07
5.3.50.0080.03812.01
5.3.40.0050.04012.01
5.3.30.0080.03311.96
5.3.20.0090.03411.74
5.3.10.0050.03911.71
5.3.00.0070.03611.69

preferences:
139.74 ms | 1394 KiB | 7 Q