3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ExpressionCalculator { private $operators = array(); public function __construct() { $operators['+'] = function ($leftOperand, $rightOperand) { return $leftOperand + $rightOperand; }; $operators['-'] = function ($leftOperand, $rightOperand) { return $leftOperand - $rightOperand; }; $operators['*'] = function ($leftOperand, $rightOperand) { return $leftOperand * $rightOperand; }; $operators['/'] = function ($leftOperand, $rightOperand) { return $leftOperand / $rightOperand; }; } public function calc($expression) { $operands = array(); while (($token = strtok($expression, ' ')) !== false) { if ($this->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)
8.3.60.0170.15965.25
8.3.50.0580.17264.88
8.3.40.0430.07042.81
8.3.30.0440.08144.41
8.3.20.0200.05344.40
8.3.10.0070.06746.13
8.3.00.0030.04846.54
8.2.180.0800.13064.64
8.2.170.0300.08743.05
8.2.160.0030.09744.63
8.2.150.0240.03742.79
8.2.140.0330.04042.85
8.2.130.0030.05346.36
8.2.120.0100.04444.85
8.2.110.0200.07144.92
8.2.100.0280.06641.83
8.2.90.0130.06743.45
8.2.80.0130.06243.50
8.2.70.0100.07441.61
8.2.60.0070.07441.89
8.2.50.0130.06441.75
8.2.40.0230.05542.56
8.2.30.0030.07443.40
8.2.20.0160.06641.74
8.2.10.0100.06641.78
8.2.00.0130.06541.68
8.1.280.0130.07751.68
8.1.270.0190.02537.91
8.1.260.0230.02036.35
8.1.250.0180.02538.20
8.1.240.0030.04239.89
8.1.230.0250.03534.92
8.1.220.0100.03733.87
8.1.210.0100.03733.40
8.1.200.0130.03533.20
8.1.190.0000.04733.59
8.1.180.0030.04435.08
8.1.170.0070.04034.62
8.1.160.0100.03335.00
8.1.150.0170.03134.80
8.1.140.0100.03533.54
8.1.130.0160.03534.01
8.1.120.0230.02333.54
8.1.110.0070.03833.43
8.1.100.0100.05033.49
8.1.90.0130.04633.59
8.1.80.0000.04433.45
8.1.70.0130.03333.45
8.1.60.0070.04233.66
8.1.50.0060.04133.48
8.1.40.0100.04133.62
8.1.30.0160.03433.56
8.1.20.0100.04133.52
8.1.10.0200.07049.68
8.1.00.0380.08349.58
8.0.300.0200.05948.70
8.0.290.0130.07548.94
8.0.280.0200.06750.32
8.0.270.0130.06849.16
8.0.260.0170.06348.73
8.0.250.0130.06948.88
8.0.240.0170.06748.68
8.0.230.0300.05648.87
8.0.220.0130.07048.80
8.0.210.0100.07448.77
8.0.200.0200.06348.90
8.0.190.0170.07348.93
8.0.180.0200.07248.96
8.0.170.0230.06648.86
8.0.160.0170.07348.68
8.0.150.0100.07948.73
8.0.140.0260.06648.73
8.0.130.0300.14077.35
8.0.120.0170.07648.84
8.0.110.0270.06148.69
8.0.100.0210.06848.88
8.0.90.0130.07648.66
8.0.80.0460.09148.75
8.0.70.0230.06348.74
8.0.60.0130.07548.78
8.0.50.0240.06448.69
8.0.30.0490.12248.83
8.0.20.0420.11749.07
8.0.10.0170.07748.81
8.0.00.0580.13048.59
7.4.330.0130.07145.56
7.4.320.0240.06848.52
7.4.300.0190.07148.35
7.4.290.0170.08048.50
7.4.280.0170.07848.50
7.4.270.0230.07548.49
7.4.260.0610.12877.37
7.4.250.0290.07248.40
7.4.240.0200.07548.45
7.4.230.0300.06648.39
7.4.220.0750.08848.38
7.4.210.0460.13548.47
7.4.200.0200.08048.59
7.4.190.0130.08048.56
7.4.160.0600.10748.44
7.4.150.0650.10448.38
7.4.140.0560.12148.45
7.4.130.0480.11848.45
7.4.120.0400.12348.49
7.4.110.0520.12148.39
7.4.100.0520.15048.52
7.4.90.0600.11148.32
7.4.80.0950.14148.29
7.4.70.0690.10248.48
7.4.60.0530.11448.46
7.4.50.0230.07948.39
7.4.40.0340.13148.48
7.4.30.0820.19048.57
7.4.00.0300.13846.73
7.3.330.0530.12877.39
7.3.320.0820.15577.23
7.3.310.0270.07048.30
7.3.300.0100.08248.16
7.3.290.0360.12848.26
7.3.280.0560.13848.26
7.3.270.0430.13248.21
7.3.260.0720.12848.29
7.3.250.0510.11748.48
7.3.240.0530.11848.50
7.3.230.0380.15348.50
7.3.210.0530.12248.41
7.3.200.0690.11448.46
7.3.190.0620.15248.32
7.3.180.0640.14148.27
7.3.170.0580.12248.27
7.3.160.0550.11348.31
7.3.120.0270.15646.81
7.2.330.0600.11748.68
7.2.320.0500.13148.82
7.2.310.0510.12848.39
7.2.300.0460.11948.71
7.2.290.0460.12648.78
7.2.60.0490.09248.88
7.2.50.0570.08148.99
7.2.00.3120.09451.42
7.1.200.0520.09847.93
7.1.100.0100.11050.19
7.1.70.0070.11849.08
7.1.60.0170.14749.38
7.1.50.0310.13749.19
7.1.00.0130.19054.27
7.0.201.8070.13047.55
7.0.140.0100.18754.21
7.0.100.0470.17352.03
7.0.90.0230.18051.89
7.0.80.0470.19052.01
7.0.70.0400.13352.16
7.0.60.0530.18051.98
7.0.50.0230.16352.38
7.0.40.0300.12036.16
7.0.30.0230.20036.14
7.0.20.0170.21736.16
7.0.10.0300.16036.00
7.0.00.0170.14336.05
5.6.280.0270.29385.65
5.6.250.0300.27785.02
5.6.240.0370.24385.12
5.6.230.0230.27085.20
5.6.220.0230.29385.23
5.6.210.0300.26784.98
5.6.200.0430.26785.63
5.6.190.0470.28385.56
5.6.180.0230.26385.46
5.6.170.0300.28785.49
5.6.160.0430.20785.61
5.6.150.0230.27385.57
5.6.140.0330.22085.63
5.6.130.0230.23785.47
5.6.120.0200.25785.62
5.6.110.0330.26385.55
5.6.100.0270.27385.56
5.6.90.0270.26385.58
5.6.80.0230.29384.94
5.6.70.0200.27784.94
5.6.60.0330.22384.95
5.6.50.0170.28384.99
5.6.40.0230.28784.90
5.6.30.0200.27084.98
5.6.20.0070.28084.89
5.6.10.0300.27384.93
5.6.00.0370.23084.80
5.5.380.0400.27085.02
5.5.370.0500.27085.07
5.5.360.0270.29384.87
5.5.350.0430.26784.97
5.5.340.0230.29785.30
5.5.330.0170.31785.30
5.5.320.0270.25385.18
5.5.310.0330.30085.45
5.5.300.0200.29385.43
5.5.290.0300.28085.39
5.5.280.0370.26785.41
5.5.270.0330.27385.44
5.5.260.0230.29785.16
5.5.250.0270.29085.21
5.5.240.0430.27784.71
5.5.230.0300.22084.84
5.5.220.0370.29384.54
5.5.210.0170.28084.78
5.5.200.0330.26784.64
5.5.190.0370.24784.77
5.5.180.0100.24084.76
5.5.160.0170.26084.70
5.5.150.0130.22784.74
5.5.140.0270.30084.68
5.5.130.0230.25784.63
5.5.120.0370.21784.80
5.5.110.0300.21784.67
5.5.100.0170.19384.62
5.5.90.0270.22084.68
5.5.80.0170.19784.60
5.5.70.0170.21084.67
5.5.60.0400.21084.52
5.5.50.0200.28384.45
5.5.40.0200.24384.68
5.5.30.0200.28084.66
5.5.20.0100.25784.68
5.5.10.0200.22384.62
5.5.00.0230.22084.61
5.4.450.0170.28784.00
5.4.440.0230.23783.81
5.4.430.0130.22783.73
5.4.420.0230.25383.64
5.4.410.0430.26783.84
5.4.400.0200.28383.58
5.4.390.0270.26783.46
5.4.380.0230.29383.51
5.4.370.0270.29783.55
5.4.360.0370.27783.50
5.4.350.0300.26783.55
5.4.340.0370.20783.31
5.4.320.0230.21783.48
5.4.310.0270.23783.55
5.4.300.0130.23383.50
5.4.290.0230.29083.49
5.4.280.0270.22083.48
5.4.270.0200.22083.49
5.4.260.0070.22783.54
5.4.250.0400.20783.55
5.4.240.0130.22783.51
5.4.230.0170.22083.49
5.4.220.0100.21783.45
5.4.210.0230.23383.49
5.4.200.0130.30383.49
5.4.190.0170.25083.44
5.4.180.0270.29783.48
5.4.170.0170.27383.56
5.4.160.0400.25783.44
5.4.150.0130.28783.44
5.4.140.0370.26780.89
5.4.130.0230.25380.96
5.4.120.0370.25080.85
5.4.110.0170.27081.01
5.4.100.0370.22780.78
5.4.90.0300.27780.83
5.4.80.0270.27380.80
5.4.70.0100.23780.77
5.4.60.0100.26780.91
5.4.50.0200.26080.84
5.4.40.0270.26780.89
5.4.30.0100.23080.95
5.4.20.0300.26080.79
5.4.10.0200.23380.91
5.4.00.0230.26780.41
5.3.290.0130.27077.88
5.3.280.0070.34077.82
5.3.270.0230.33777.77
5.3.260.0170.33377.77
5.3.250.0170.32077.76
5.3.240.0070.32377.73
5.3.230.0230.32777.86
5.3.220.0200.31077.70
5.3.210.0170.36077.79
5.3.200.0130.31777.70
5.3.190.0200.37777.78
5.3.180.0270.30377.80
5.3.170.0230.32077.77
5.3.160.0230.29377.85
5.3.150.0200.34077.83
5.3.140.0200.30077.78
5.3.130.0300.30377.67
5.3.120.0300.30777.67
5.3.110.0230.29077.76
5.3.100.0230.30377.31
5.3.90.0230.31777.19
5.3.80.0270.26077.21
5.3.70.0230.33377.21
5.3.60.0270.32077.13
5.3.50.0100.26776.97
5.3.40.0270.30077.21
5.3.30.0370.32377.02
5.3.20.0100.33376.96
5.3.10.0230.32376.78
5.3.00.0300.32776.78
5.2.170.0070.03311.23
5.2.160.0000.06711.26
5.2.150.0000.05311.15
5.2.140.0030.03311.09
5.2.130.0070.03311.01
5.2.120.0100.04011.16
5.2.110.0030.06311.02
5.2.100.0070.03011.11
5.2.90.0030.05711.02
5.2.80.0030.03011.15
5.2.70.0070.05711.21
5.2.60.0070.06011.08
5.2.50.0000.06311.13
5.2.40.0070.05311.06
5.2.30.0030.06311.06
5.2.20.0070.06011.02
5.2.10.0030.05311.00
5.2.00.0070.05710.72
5.1.60.0030.0579.84
5.1.50.0030.05310.02
5.1.40.0100.02710.05
5.1.30.0070.06010.39
5.1.20.0070.05010.29
5.1.10.0030.05710.06
5.1.00.0070.0539.95
5.0.50.0000.0479.03
5.0.40.0100.0379.03
5.0.30.0000.0679.03
5.0.20.0030.0409.03
5.0.10.0000.0479.03
5.0.00.0030.0479.03
4.4.90.0000.0379.03
4.4.80.0030.0339.03
4.4.70.0030.0339.03
4.4.60.0000.0209.03
4.4.50.0000.0309.03
4.4.40.0000.0609.03
4.4.30.0070.0309.03
4.4.20.0030.0339.03
4.4.10.0000.0379.03
4.4.00.0030.0379.03
4.3.110.0000.0409.03
4.3.100.0000.0379.03
4.3.90.0000.0379.03
4.3.80.0030.0479.03
4.3.70.0000.0379.03
4.3.60.0000.0309.03
4.3.50.0000.0409.03
4.3.40.0030.0479.03
4.3.30.0000.0379.03
4.3.20.0000.0309.03
4.3.10.0000.0339.03
4.3.00.0030.0379.03

preferences:
50.46 ms | 401 KiB | 5 Q