3v4l.org

run code in 300+ PHP versions simultaneously
<?php // conditionally define PHP_INT_MIN since PHP 5.x doesn't // include it and it's needed to validate integer casts if (!defined("PHP_INT_MIN")) { define("PHP_INT_MIN", ~PHP_INT_MAX); } var_dump(to_int((float) PHP_INT_MAX) === PHP_INT_MAX); /** * Returns the value as an int, or false if it cannot be safely cast * @param mixed $val * @return int */ function to_int($val) { switch (gettype($val)) { case "integer": return $val; case "double": if (!is_infinite($val) && !is_nan($val) && $val >= PHP_INT_MIN) { // due to rounding issues, on 64-bit platforms // the float must be less than PHP_INT_MAX if ( (PHP_INT_SIZE === 8 && $val < PHP_INT_MAX) || // valid 64-bit (PHP_INT_SIZE !== 8 && $val <= PHP_INT_MAX) // valid non-64-bit ) { return (int) $val; // valid floats should cast } } return false; case "string": $val = trim($val, " \t\n\r\v\f"); // trim whitespace return filter_var($val, FILTER_VALIDATE_INT); default: return false; } }

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.0110.00718.18
8.3.50.0110.00822.12
8.3.40.0140.00718.71
8.3.30.0040.01118.96
8.3.20.0080.00020.04
8.3.10.0040.00420.20
8.3.00.0040.00417.50
8.2.180.0150.00318.18
8.2.170.0040.01122.96
8.2.160.0100.00618.91
8.2.150.0080.00024.18
8.2.140.0030.00524.66
8.2.130.0040.00426.16
8.2.120.0040.00420.97
8.2.110.0060.00322.07
8.2.100.0000.01217.72
8.2.90.0090.00019.26
8.2.80.0000.00817.97
8.2.70.0040.00417.63
8.2.60.0030.00517.90
8.2.50.0040.00418.07
8.2.40.0000.00818.09
8.2.30.0070.00019.11
8.2.20.0090.00017.66
8.2.10.0000.00718.09
8.2.00.0050.00317.66
8.1.280.0090.00925.92
8.1.270.0000.00822.20
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0030.00622.20
8.1.230.0030.00719.16
8.1.220.0000.00817.74
8.1.210.0030.00918.77
8.1.200.0080.00317.25
8.1.190.0080.00017.23
8.1.180.0050.00318.10
8.1.170.0060.00618.64
8.1.160.0040.00421.96
8.1.150.0070.00018.72
8.1.140.0000.00817.37
8.1.130.0030.00317.71
8.1.120.0000.00817.41
8.1.110.0000.00817.25
8.1.100.0040.00417.43
8.1.90.0030.00317.27
8.1.80.0040.00417.40
8.1.70.0000.00717.32
8.1.60.0030.00617.54
8.1.50.0050.00217.33
8.1.40.0070.00017.44
8.1.30.0050.00317.55
8.1.20.0000.00717.66
8.1.10.0050.00317.34
8.1.00.0030.00617.22
8.0.300.0070.00018.77
8.0.290.0060.00316.63
8.0.280.0030.00318.34
8.0.270.0000.00817.17
8.0.260.0000.00718.24
8.0.250.0000.00716.94
8.0.240.0000.00716.83
8.0.230.0030.00317.00
8.0.220.0000.00716.93
8.0.210.0000.00716.77
8.0.200.0040.00416.93
8.0.190.0050.00316.93
8.0.180.0000.00716.82
8.0.170.0000.00816.99
8.0.160.0040.00416.93
8.0.150.0070.00016.82
8.0.140.0040.00816.77
8.0.130.0000.00513.38
8.0.120.0050.00216.87
8.0.110.0040.00416.88
8.0.100.0000.00716.88
8.0.90.0070.00016.75
8.0.80.0120.00916.84
8.0.70.0000.00716.79
8.0.60.0040.00416.70
8.0.50.0030.00516.73
8.0.30.0080.01117.06
8.0.20.0100.00817.40
8.0.10.0040.00416.95
8.0.00.0120.00816.75
7.4.330.0000.00515.00
7.4.320.0030.00316.55
7.4.300.0030.00316.53
7.4.290.0040.00416.52
7.4.280.0070.00416.32
7.4.270.0030.00516.52
7.4.260.0020.00516.55
7.4.250.0000.00716.37
7.4.240.0070.00016.49
7.4.230.0070.00016.32
7.4.220.0100.00716.52
7.4.210.0030.01016.52
7.4.200.0000.00716.51
7.4.160.0030.01416.49
7.4.150.0050.01317.40
7.4.140.0100.00717.86
7.4.130.0120.00816.60
7.4.120.0060.01116.50
7.4.110.0080.00816.55
7.4.100.0030.01416.38
7.4.90.0150.00316.50
7.4.80.0030.01318.80
7.4.70.0110.00516.52
7.4.60.0070.01416.64
7.4.50.0020.00216.39
7.4.40.0050.01316.45
7.4.30.0090.00616.39
7.4.00.0090.00614.99
7.3.330.0000.00613.12
7.3.320.0030.00313.28
7.3.310.0040.00416.41
7.3.300.0000.00716.23
7.3.290.0070.00716.27
7.3.280.0080.00816.37
7.3.270.0030.01317.40
7.3.260.0110.00716.61
7.3.250.0170.00316.47
7.3.240.0060.01016.33
7.3.230.0070.01016.39
7.3.210.0030.01316.35
7.3.200.0090.01019.39
7.3.190.0150.00416.70
7.3.180.0030.01416.27
7.3.170.0110.00616.59
7.3.160.0060.00916.46
7.2.330.0100.01316.56
7.2.320.0130.00316.55
7.2.310.0130.00316.38
7.2.300.0130.00916.79
7.2.290.0100.00616.46
7.2.00.0050.00819.58
7.1.100.0040.00717.97
7.1.70.0090.00317.01
7.1.60.0030.02119.32
7.1.50.0130.01316.93
7.1.00.0030.07722.45
7.0.200.0030.00616.57
7.0.140.0000.07721.97
7.0.60.0100.08320.07
7.0.50.0030.08317.74
7.0.40.0070.05020.30
7.0.30.0200.05720.07
7.0.20.0400.07320.33
7.0.10.0070.09020.23
7.0.00.0130.08020.09
5.6.280.0030.09320.82
5.6.210.0030.06020.77
5.6.200.0000.04318.25
5.6.190.0000.04720.61
5.6.180.0530.06320.42
5.6.170.0200.04320.48
5.6.160.0100.07720.50
5.6.150.0070.07718.15
5.6.140.0130.07318.23
5.6.130.0070.04718.11
5.6.120.0100.08020.79
5.6.110.0030.07720.94
5.6.100.0030.08320.97
5.6.90.0070.04320.98
5.6.80.0000.04320.38
5.5.350.0230.04720.41
5.5.340.0130.05317.98
5.5.330.0030.04020.19
5.5.320.0400.07020.29
5.5.310.0130.04720.31
5.5.300.0130.03018.08
5.5.290.0030.04317.93
5.5.280.0200.07720.90
5.5.270.0070.08320.75
5.5.260.0130.08020.64
5.5.250.0070.06020.71
5.5.240.0200.07720.19
5.4.450.0230.04019.53
5.4.440.0830.06319.34
5.4.430.0930.05719.60
5.4.420.0670.00019.68
5.4.410.0630.00019.25
5.4.400.0630.00019.22
5.4.390.0670.00019.06
5.4.380.0470.04718.63
5.4.370.0270.06718.76
5.4.360.0370.06718.72
5.4.350.0300.06018.81
5.4.340.0230.06318.61
5.4.320.0120.03412.51
5.4.310.0080.04512.50
5.4.300.0090.04412.50
5.4.290.0070.03712.50
5.4.280.0090.03312.40
5.4.270.0070.03512.40
5.4.260.0070.03712.40
5.4.250.0080.04312.40
5.4.240.0020.04112.40
5.4.230.0080.03812.39
5.4.220.0060.04512.39
5.4.210.0080.03412.39
5.4.200.0060.03712.39
5.4.190.0040.03712.39
5.4.180.0060.03712.39
5.4.170.0060.05312.39
5.4.160.0050.04012.39
5.4.150.0070.03512.39
5.4.140.0050.03812.07
5.4.130.0070.03812.06
5.4.120.0080.03812.01
5.4.110.0050.03512.02
5.4.100.0080.03412.02
5.4.90.0060.03712.01
5.4.80.0080.03612.01
5.4.70.0040.03612.01
5.4.60.0070.03512.01
5.4.50.0030.03612.01
5.4.40.0060.03312.00
5.4.30.0060.03411.99
5.4.20.0060.03811.99
5.4.10.0070.03511.99
5.4.00.0080.04011.48
5.3.290.0070.04012.80
5.3.280.0060.04312.71
5.3.270.0090.03612.73
5.3.260.0090.04112.72
5.3.250.0080.03512.72
5.3.240.0030.04212.72
5.3.230.0060.03812.70
5.3.220.0070.03712.68
5.3.210.0070.04712.68
5.3.200.0070.03712.68
5.3.190.0100.03612.68
5.3.180.0080.03612.68
5.3.170.0070.03912.67
5.3.160.0070.03912.67
5.3.150.0050.03812.68
5.3.140.0060.03512.66
5.3.130.0070.03812.66
5.3.120.0070.04012.66
5.3.110.0040.04512.65
5.3.100.0030.04012.11
5.3.90.0060.03612.10
5.3.80.0050.04212.09
5.3.70.0050.03812.09
5.3.60.0090.03512.07
5.3.50.0080.03312.02
5.3.40.0050.03712.02
5.3.30.0050.03511.98
5.3.20.0070.04711.76
5.3.10.0070.04511.73
5.3.00.0040.03811.72
5.2.170.0070.0419.23
5.2.160.0070.0299.23
5.2.150.0050.0359.23
5.2.140.0050.0329.22
5.2.130.0040.0319.18
5.2.120.0040.0319.19
5.2.110.0060.0289.20
5.2.100.0060.0279.19
5.2.90.0070.0279.19
5.2.80.0050.0309.19
5.2.70.0040.0339.19
5.2.60.0040.0329.14
5.2.50.0050.0309.11
5.2.40.0020.0319.09
5.2.30.0020.0329.05
5.2.20.0050.0329.05
5.2.10.0060.0278.95
5.2.00.0040.0298.82
5.1.60.0060.0308.11
5.1.50.0070.0248.10
5.1.40.0030.0268.08
5.1.30.0070.0238.43
5.1.20.0050.0268.45
5.1.10.0020.0298.18
5.1.00.0020.0318.18
5.0.50.0030.0226.66
5.0.40.0030.0216.52
5.0.30.0060.0296.33
5.0.20.0040.0216.30
5.0.10.0060.0186.28
5.0.00.0040.0326.27
4.4.90.0040.0154.78
4.4.80.0030.0154.75
4.4.70.0020.0164.75
4.4.60.0030.0154.76
4.4.50.0010.0174.77
4.4.40.0010.0274.71
4.4.30.0010.0174.76
4.4.20.0030.0164.84
4.4.10.0010.0174.84
4.4.00.0020.0264.75
4.3.110.0050.0134.67
4.3.100.0030.0154.67
4.3.90.0050.0144.64
4.3.80.0040.0294.58
4.3.70.0020.0194.63
4.3.60.0010.0164.62
4.3.50.0040.0144.63
4.3.40.0020.0264.54
4.3.30.0030.0153.32
4.3.20.0020.0163.30
4.3.10.0020.0173.26
4.3.00.0200.01316.39

preferences:
70.52 ms | 401 KiB | 5 Q