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) { echo $token; 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.70.0530.02018.13
8.3.60.0580.02420.43
8.3.50.0680.01423.09
8.3.40.0700.01720.64
8.3.30.0750.01321.75
8.3.20.0290.01021.87
8.3.10.0380.00324.13
8.3.00.0240.01424.34
8.2.180.0450.02117.88
8.2.170.0590.02322.96
8.2.160.0620.02024.08
8.2.150.0340.00724.18
8.2.140.0260.01024.66
8.2.130.0300.01326.16
8.2.120.0370.00321.96
8.2.110.0430.00724.35
8.2.100.0420.01619.33
8.2.90.0140.01420.70
8.2.80.0070.01820.95
8.2.70.0140.01419.50
8.2.60.0070.02420.05
8.2.50.0170.01319.00
8.2.40.0150.01519.66
8.2.30.0230.00621.57
8.2.20.0140.01419.41
8.2.10.0210.00919.29
8.2.00.0280.00319.37
8.1.280.0450.01925.92
8.1.270.0360.00423.99
8.1.260.0180.01826.35
8.1.250.0320.01028.09
8.1.240.0380.01025.85
8.1.230.0470.00721.09
8.1.220.0220.00719.65
8.1.210.0160.01319.36
8.1.200.0140.01719.25
8.1.190.0170.01019.66
8.1.180.0210.00721.20
8.1.170.0260.00720.66
8.1.160.0230.00320.88
8.1.150.0070.02420.61
8.1.140.0200.01019.56
8.1.130.0130.01320.23
8.1.120.0100.01719.54
8.1.110.0070.02619.45
8.1.100.0140.01920.10
8.1.90.0150.01919.61
8.1.80.0070.01819.58
8.1.70.0180.00619.53
8.1.60.0160.01019.59
8.1.50.0200.00719.52
8.1.40.0130.01319.63
8.1.30.0160.01319.70
8.1.20.0130.01319.58
8.1.10.0190.00619.66
8.1.00.0250.01019.66
8.0.300.0220.00618.79
8.0.290.0190.00619.05
8.0.280.0130.01921.31
8.0.270.0170.01019.32
8.0.260.0200.01018.79
8.0.250.0120.01218.99
8.0.240.0200.01019.62
8.0.230.0210.00718.84
8.0.220.0180.00918.77
8.0.210.0180.01118.75
8.0.200.0100.01718.86
8.0.190.0170.01418.98
8.0.180.0200.00718.88
8.0.170.0160.01018.92
8.0.160.0150.01518.93
8.0.150.0130.01718.87
8.0.140.0130.01618.83
8.0.130.0190.00615.38
8.0.120.0160.01018.87
8.0.110.0250.00318.89
8.0.100.0210.00318.71
8.0.90.0070.02119.75
8.0.80.0470.04118.86
8.0.70.0160.01318.69
8.0.60.0070.01819.48
8.0.50.0040.02319.17
8.0.30.1090.06319.52
8.0.20.1150.05419.76
8.0.10.0130.01319.01
8.0.00.1040.08318.71
7.4.330.0200.00717.09
7.4.320.0170.01018.42
7.4.300.0100.01618.49
7.4.290.0130.01318.54
7.4.280.0130.01619.57
7.4.270.0230.00718.54
7.4.260.0140.01415.22
7.4.250.0170.01018.27
7.4.240.0100.02318.43
7.4.230.0100.01419.67
7.4.220.0380.12219.73
7.4.210.0390.05618.76
7.4.200.0140.01418.38
7.4.190.0130.01318.29
7.4.160.0710.07519.46
7.4.150.1160.08218.53
7.4.140.1280.07418.46
7.4.130.1080.07918.97
7.4.120.1250.07618.39
7.4.110.0890.09718.36
7.4.100.1090.04919.52
7.4.90.0840.07719.79
7.4.80.0760.09519.39
7.4.70.0720.06918.37
7.4.60.0560.06718.23
7.4.50.0250.01918.30
7.4.40.0240.04122.77
7.4.30.0690.06619.52
7.4.00.0300.03717.90
7.3.330.0150.01115.25
7.3.320.0250.00615.44
7.3.310.0150.01518.26
7.3.300.0190.00918.21
7.3.290.0360.09918.20
7.3.280.0540.07819.34
7.3.270.0890.06919.35
7.3.260.1150.05718.26
7.3.250.1040.05518.90
7.3.240.1200.05219.70
7.3.230.0940.06418.37
7.3.210.0990.07219.47
7.3.200.0650.06219.39
7.3.190.0890.06118.67
7.3.180.0700.08118.45
7.3.170.0600.06318.23
7.3.160.0470.07018.44
7.3.120.0420.02617.67
7.2.330.1080.07318.64
7.2.320.0590.10719.34
7.2.310.0790.05918.67
7.2.300.0810.05118.51
7.2.290.0680.06418.73
7.2.00.0240.01723.36
7.1.100.1060.01619.88
7.1.70.0260.00319.25
7.1.60.0170.02119.48
7.1.50.0370.03019.08
7.1.00.0300.04024.41
7.0.200.0390.02918.52
7.0.140.0270.09323.95
7.0.100.0530.07722.99
7.0.90.0270.09322.01
7.0.80.0600.08022.09
7.0.70.0570.07723.42
7.0.60.0730.08023.16
7.0.50.0570.07323.51
7.0.40.0370.09321.39
7.0.30.0330.07020.11
7.0.20.0330.07319.96
7.0.10.0300.04320.03
7.0.00.0300.06720.04
5.6.280.0370.11326.51
5.6.250.0330.08026.68
5.6.240.0400.08326.20
5.6.230.0530.06326.35
5.6.220.0270.11027.05
5.6.210.0500.09726.36
5.6.200.0400.08726.56
5.6.190.0200.06727.07
5.6.180.0530.10326.64
5.6.170.0630.06726.66
5.6.160.0300.05328.62
5.6.150.0270.06026.66
5.6.140.0500.09726.59
5.6.130.0300.06027.27
5.6.120.0370.05726.66
5.6.110.0500.11326.53
5.6.100.0570.14026.62
5.6.90.0300.05726.94
5.6.80.0370.10026.05
5.6.70.0270.06327.23
5.6.60.0370.08726.13
5.6.50.0430.07726.20
5.6.40.0330.10326.09
5.6.30.0370.08026.09
5.6.20.0300.06026.04
5.6.10.0400.08326.04
5.6.00.0430.06026.00
5.5.380.0370.05726.84
5.5.370.0370.09726.07
5.5.360.0930.13026.02
5.5.350.0930.11726.17
5.5.340.0970.13326.54
5.5.330.0530.09726.54
5.5.320.0730.06326.56
5.5.310.0700.11326.34
5.5.300.0400.11026.56
5.5.290.0700.13026.47
5.5.280.0700.13726.54
5.5.270.0330.10026.41
5.5.260.0800.09026.53
5.5.250.0600.09326.36
5.5.240.0330.13025.85
5.5.230.0570.10725.84
5.5.220.0670.06725.79
5.5.210.0870.12325.94
5.5.200.1130.12025.91
5.5.190.0700.10026.16
5.5.180.0430.09026.25
5.5.160.0900.10725.89
5.5.150.0530.07325.89
5.5.140.1000.10325.89
5.5.130.1230.12725.81
5.5.120.0500.07725.89
5.5.110.0570.12025.81
5.5.100.1000.13725.80
5.5.90.0930.14725.68
5.5.80.0430.08725.79
5.5.70.0770.10725.63
5.5.60.0800.12325.73
5.5.50.0600.06725.82
5.5.40.0630.08326.44
5.5.30.0500.10325.91
5.5.20.0930.10725.74
5.5.10.0770.11325.68
5.5.00.0400.10325.54
5.4.450.1130.14724.82
5.4.440.0930.11025.15
5.4.430.0430.08324.87
5.4.420.0770.10324.87
5.4.410.0970.11324.85
5.4.400.1000.11025.50
5.4.390.0730.12724.45
5.4.380.0730.10324.45
5.4.370.0970.12324.69
5.4.360.0600.12025.18
5.4.350.0870.10324.50
5.4.340.0730.13024.91
5.4.320.0470.08724.66
5.4.310.0630.10324.70
5.4.300.0400.08724.54
5.4.290.1000.11724.66
5.4.280.0730.10024.45
5.4.270.0500.10324.65
5.4.260.0600.06324.70
5.4.250.0630.10024.68
5.4.240.0700.11024.69
5.4.230.0330.09724.66
5.4.220.0500.09724.63
5.4.210.0330.09324.51
5.4.200.0300.09324.65
5.4.190.0400.08024.81
5.4.180.0700.13024.77
5.4.170.0600.11024.66
5.4.160.0770.11724.47
5.4.150.0600.09324.77
5.4.140.0500.13722.20
5.4.130.0470.07722.08
5.4.120.0700.11721.85
5.4.110.0830.10322.12
5.4.100.0730.12321.93
5.4.90.0700.09722.03
5.4.80.0870.11721.85
5.4.70.0370.09721.92
5.4.60.0730.12322.15
5.4.50.1070.15722.12
5.4.40.0270.11321.98
5.4.30.0630.08321.84
5.4.20.0730.09322.07
5.4.10.0400.08322.09
5.4.00.0800.08321.75
5.3.290.0870.10019.89
5.3.280.0570.07319.94
5.3.270.0930.10319.84
5.3.260.0770.10320.00
5.3.250.0470.11719.99
5.3.240.0770.13720.00
5.3.230.0370.09719.93
5.3.220.0570.07719.91
5.3.210.0870.14319.91
5.3.200.0600.10019.97
5.3.190.0830.13720.23
5.3.180.0870.10720.23
5.3.170.0870.11719.90
5.3.160.0900.11019.95
5.3.150.0630.12719.94
5.3.140.0630.10319.79
5.3.130.0530.11319.91
5.3.120.1100.13319.90
5.3.110.0470.15020.14
5.3.100.1030.10719.41
5.3.90.1230.15019.51
5.3.80.0570.13019.15
5.3.70.0600.11019.34
5.3.60.0770.15019.32
5.3.50.1170.14719.26
5.3.40.0470.09019.24
5.3.30.0670.10319.21
5.3.20.0600.13019.05
5.3.10.0530.10018.95
5.3.00.2070.20318.91
5.2.170.0000.06315.66
5.2.160.0030.03715.66
5.2.150.0000.06715.66
5.2.140.0070.06015.66
5.2.130.0100.05015.66
5.2.120.0000.03315.66
5.2.110.0030.04015.66
5.2.100.0100.05715.66
5.2.90.0070.05315.66
5.2.80.0100.05315.66
5.2.70.0000.03015.66
5.2.60.0030.04715.66
5.2.50.0070.05715.66
5.2.40.0130.04315.66
5.2.30.0030.06015.66
5.2.20.0030.05715.66
5.2.10.0000.06715.66
5.2.00.0100.05715.66
5.1.60.0030.05315.66
5.1.50.0000.03715.66
5.1.40.0000.04315.66
5.1.30.0030.05715.66
5.1.20.0030.03315.66
5.1.10.0030.04715.66
5.1.00.0100.04015.66
5.0.50.0030.02315.66
5.0.40.0070.01715.66
5.0.30.0030.05015.66
5.0.20.0070.04015.66
5.0.10.0070.04015.66
5.0.00.0100.05015.66
4.4.90.0130.02015.66
4.4.80.0030.03315.66
4.4.70.0070.03315.66
4.4.60.0000.03715.66
4.4.50.0030.03015.66
4.4.40.0070.05015.66
4.4.30.0000.02315.66
4.4.20.0030.03715.66
4.4.10.0030.03315.66
4.4.00.0000.03715.66
4.3.110.0000.03315.66
4.3.100.0030.03315.66
4.3.90.0000.03715.66
4.3.80.0030.05015.66
4.3.70.0030.01715.66
4.3.60.0030.03315.66
4.3.50.0070.01715.66
4.3.40.0030.05015.66
4.3.30.0000.03015.66
4.3.20.0000.01715.66
4.3.10.0030.02015.66
4.3.00.0070.02715.66

preferences:
37.29 ms | 401 KiB | 5 Q