3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param $x * @return int * @throws Exception */ function castToInt($x) { $result = intval($x); if ($x === $result) { return $result; } throw new \Exception("Not an int"); } /** * @param $x * @return bool */ function isInt($x) { return ($x === intval($x)); } error_reporting(-1); $time = microtime(TRUE); $even = $odd = array(); foreach (range(1, 100000) as $i) { $value = $i / 2; if (isInt($value)) { $even[] = $value; } } $isIntTime = microtime(TRUE) - $time; $time = microtime(TRUE); $even = $odd = array(); foreach (range(1, 100000) as $i) { try { $value = castToInt($i/2); $even[] = $value; } catch (\Exception $e) { //we don't care about unparseable stuff. } } $castExceptionTime = microtime(TRUE) - $time; echo 'castException microtime: '.$castExceptionTime.PHP_EOL; echo 'isInt microtime: '.$isIntTime.PHP_EOL; $ratioSlower = round($castExceptionTime / $isIntTime, 1); echo "Exception version is ".$ratioSlower." times slower.".PHP_EOL;

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)
7.3.10.0220.05022.44
7.3.00.0200.05522.62
7.2.130.0190.06022.88
7.2.120.0190.05922.89
7.2.110.0180.05722.79
7.2.100.0180.05722.88
7.2.90.0130.06023.04
7.2.80.0150.05722.83
7.2.70.0160.05922.91
7.2.60.0170.05422.83
7.2.50.0200.05922.74
7.2.40.0130.05822.83
7.2.30.0180.05822.92
7.2.20.0150.05722.89
7.2.10.0160.06022.91
7.2.00.0130.06022.81
7.1.250.0140.08621.78
7.1.240.0200.08421.77
7.1.230.0210.08421.56
7.1.220.0300.07921.86
7.1.210.0140.08921.70
7.1.200.0230.07321.82
7.1.190.0170.07721.54
7.1.180.0170.07821.60
7.1.170.0270.09621.53
7.1.160.0410.07921.79
7.1.150.0350.08021.91
7.1.140.0200.07721.71
7.1.130.0330.07821.82
7.1.120.0260.08221.61
7.1.110.0280.07821.65
7.1.100.0220.07821.59
7.1.90.0200.08121.83
7.1.80.0260.08521.87
7.1.70.0170.06322.29
7.1.60.0130.08822.50
7.1.50.0100.09022.21
7.1.40.0250.07521.93
7.1.30.0330.06821.84
7.1.20.0230.07821.45
7.1.10.0170.08121.46
7.1.00.0070.11524.95
7.0.330.0170.10021.24
7.0.320.0140.09921.59
7.0.310.0200.09821.39
7.0.300.0200.11121.44
7.0.290.0130.10521.59
7.0.280.0230.10821.05
7.0.270.0180.10921.47
7.0.260.0180.11421.26
7.0.250.0190.10921.24
7.0.240.0230.10621.18
7.0.230.0260.09621.54
7.0.220.0360.09521.30
7.0.210.0330.09921.46
7.0.200.0150.08122.15
7.0.190.0270.10821.20
7.0.180.0160.10721.53
7.0.170.0200.10021.54
7.0.160.0110.10921.23
7.0.150.0200.10921.38
7.0.140.0100.13224.80
7.0.130.0200.10221.51
7.0.120.0100.11021.50
7.0.110.0170.12021.15
7.0.100.0100.10421.30
7.0.90.0140.10421.50
7.0.80.0230.09821.27
7.0.70.0130.09521.24
7.0.60.0140.10623.42
7.0.50.0150.10422.32
7.0.40.0150.10121.97
7.0.30.0270.10421.85
7.0.20.0280.09921.66
7.0.10.0080.10121.96
7.0.00.0070.10321.81
5.6.380.0100.22635.66
5.6.370.0130.22235.71
5.6.360.0440.21035.64
5.6.350.0460.20935.62
5.6.340.0330.21635.96
5.6.330.0160.22535.51
5.6.320.0260.22235.56
5.6.310.0330.22235.56
5.6.300.0430.20035.32
5.6.290.0260.23735.79
5.6.280.0180.24538.84
5.6.270.0330.22035.21
5.6.260.0320.20435.35
5.6.250.0330.21635.22
5.6.240.0240.21735.68
5.6.230.0300.23234.96
5.6.220.0350.20135.39
5.6.210.0150.20638.38
5.6.200.0300.20037.20
5.6.190.0360.22738.48
5.6.180.0550.20138.47
5.6.170.0300.18838.42
5.6.160.0220.19238.16
5.6.150.0220.20937.21
5.6.140.0210.22337.48
5.6.130.0220.21237.34
5.6.120.0370.19738.84
5.6.110.0230.19238.72
5.6.100.0200.22638.90
5.6.90.0170.19138.85
5.6.80.0220.21938.67
5.6.70.0360.21335.39
5.6.60.0230.22135.25
5.6.50.0260.20135.04
5.6.40.0370.20635.61
5.6.30.0420.19835.56
5.6.20.0360.21135.30
5.6.10.0100.23635.68
5.6.00.0350.21035.45
5.5.380.0260.20932.53
5.5.370.0200.24332.11
5.5.360.0170.21432.18
5.5.350.0280.21336.76
5.5.340.0220.19935.59
5.5.330.0280.21336.67
5.5.320.0220.20036.72
5.5.310.0270.19736.80
5.5.300.0240.20435.58
5.5.290.0270.20535.75
5.5.280.0290.20536.99
5.5.270.0230.21836.89
5.5.260.0350.16937.06
5.5.250.0270.20236.99
5.5.240.0270.22636.67
5.5.230.0260.20932.20
5.5.220.0300.21632.20
5.5.210.0290.20632.30
5.5.200.0360.20832.11
5.5.190.0160.21631.90
5.5.180.0290.22232.31
5.5.170.0200.21432.00
5.5.160.0390.20032.38
5.5.150.0290.20632.45
5.5.140.0260.22731.90
5.5.130.0270.21032.27
5.5.120.0240.21132.06
5.5.110.0270.20732.35
5.5.100.0130.23532.25
5.5.90.0230.20431.98
5.5.80.0200.21732.07
5.5.70.0330.20732.27
5.5.60.0230.21032.33
5.5.50.0360.20132.37
5.5.40.0130.23832.41
5.5.30.0140.21832.36
5.5.20.0200.20832.25
5.5.10.0330.20932.49
5.5.00.0170.22232.14
5.4.450.0230.24936.43
5.4.440.0670.29236.49
5.4.430.0350.23336.35
5.4.420.0220.27236.36
5.4.410.0250.26436.36
5.4.400.0420.24636.28
5.4.390.0250.26036.13
5.4.380.0200.26036.04
5.4.370.0350.24836.09
5.4.360.0330.23436.13
5.4.350.0250.24836.19
5.4.340.0160.24432.75
5.4.330.0100.21732.26
5.4.320.0230.25732.93
5.4.310.0200.22132.87
5.4.300.0220.21632.81
5.4.290.0270.20932.87
5.4.280.0220.24532.70
5.4.270.0140.23032.78
5.4.260.0230.23432.89
5.4.250.0230.26832.80
5.4.240.0230.22132.83
5.4.230.0110.22732.89
5.4.220.0210.20332.82
5.4.210.0150.22132.86
5.4.200.0150.16632.77
5.4.190.0190.22732.82
5.4.180.0190.21532.61
5.4.170.0150.22132.89
5.4.160.0240.21232.77
5.4.150.0190.20632.89
5.4.140.0170.21632.72
5.4.130.0150.22532.56
5.4.120.0200.23632.64
5.4.110.0240.21632.54
5.4.100.0200.23632.64
5.4.90.0120.21732.64
5.4.80.0130.22432.43
5.4.70.0200.24632.68
5.4.60.0250.28232.63
5.4.50.0230.23432.58
5.4.40.0200.21432.43
5.4.30.0220.25032.68
5.4.20.0200.22532.64
5.4.10.0200.21832.55
5.4.00.0180.22332.26
5.3.290.0150.26533.64
5.3.280.0100.27433.53
5.3.270.0130.27333.58
5.3.260.0120.26533.56
5.3.250.0170.26833.59
5.3.240.0120.26933.49
5.3.230.0190.29933.41
5.3.220.0130.29033.32
5.3.210.0180.27433.47
5.3.200.0160.28733.50
5.3.190.0190.26433.52
5.3.180.0100.27333.59
5.3.170.0110.29033.60
5.3.160.0110.29733.41
5.3.150.0180.28933.59
5.3.140.0150.28333.51
5.3.130.0180.26833.37
5.3.120.0140.30533.41
5.3.110.0110.27733.57
5.3.100.0170.28533.30
5.3.90.0170.28233.30
5.3.80.0110.26033.21
5.3.70.0160.29333.19
5.3.60.0090.29233.02
5.3.50.0170.26133.16
5.3.40.0160.26333.01
5.3.30.0100.26333.17
5.3.20.0110.27832.89
5.3.10.0100.26732.74
5.3.00.0150.26932.77
5.2.170.0160.27829.78
5.2.160.0150.27529.58
5.2.150.0120.27329.62
5.2.140.0150.26429.67
5.2.130.0120.29329.71
5.2.120.0140.27229.71
5.2.110.0130.27029.71
5.2.100.0140.28829.70
5.2.90.0140.30629.71
5.2.80.0090.30529.67
5.2.70.0160.28229.70
5.2.60.0090.30529.63
5.2.50.0130.32328.95
5.2.40.0120.31528.98
5.2.30.0120.30228.77
5.2.20.0140.30028.77
5.2.10.0100.26628.57
5.2.00.0110.27228.55
5.1.60.0160.30935.04
5.1.50.0130.30535.03
5.1.40.0170.30135.12
5.1.30.0130.29435.13
5.1.20.0150.31835.27
5.1.10.0110.30335.17
5.1.00.0090.30535.04
5.0.50.0180.44433.75
5.0.40.0160.45733.54
5.0.30.0090.46433.42
5.0.20.0210.42333.43
5.0.10.0150.46533.42
5.0.00.0200.43633.45
4.4.90.0030.0106.77
4.4.80.0030.0076.76
4.4.70.0030.0116.76
4.4.60.0030.0096.76
4.4.50.0020.0116.77
4.4.40.0030.0156.74
4.4.30.0010.0116.77
4.4.20.0020.0116.81
4.4.10.0020.0116.81
4.4.00.0030.0166.77
4.3.110.0030.0106.72
4.3.100.0040.0116.72
4.3.90.0020.0126.70
4.3.80.0040.0136.68
4.3.70.0020.0106.70
4.3.60.0020.0116.70
4.3.50.0030.0096.70
4.3.40.0040.0136.65
4.3.30.0010.0116.03
4.3.20.0010.0106.02
4.3.10.0040.0086.01
4.3.00.0030.0127.94

preferences:
64.28 ms | 1697 KiB | 5 Q