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(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.0120.00318.51
8.3.50.0080.01121.89
8.3.40.0120.00318.85
8.3.30.0100.00719.02
8.3.20.0060.00320.39
8.3.10.0060.00320.53
8.3.00.0040.00417.59
8.2.180.0150.00618.41
8.2.170.0070.00722.96
8.2.160.0130.00320.27
8.2.150.0090.00024.18
8.2.140.0040.00424.66
8.2.130.0070.00026.16
8.2.120.0050.00221.98
8.2.110.0060.00320.57
8.2.100.0040.00717.97
8.2.90.0080.00018.98
8.2.80.0080.00017.97
8.2.70.0080.00017.38
8.2.60.0000.00717.68
8.2.50.0060.00618.07
8.2.40.0070.00018.03
8.2.30.0000.00719.13
8.2.20.0020.00517.54
8.2.10.0080.00017.96
8.2.00.0080.00017.63
8.1.280.0070.01025.92
8.1.270.0080.00022.14
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0050.00523.58
8.1.230.0040.00719.22
8.1.220.0050.00217.74
8.1.210.0030.00518.77
8.1.200.0000.01017.11
8.1.190.0040.00416.99
8.1.180.0040.00418.10
8.1.170.0020.00918.36
8.1.160.0070.00022.01
8.1.150.0040.00418.82
8.1.140.0070.00317.40
8.1.130.0070.00017.69
8.1.120.0000.00717.29
8.1.110.0000.00817.36
8.1.100.0030.00417.38
8.1.90.0000.00817.32
8.1.80.0040.00417.39
8.1.70.0000.00817.36
8.1.60.0090.00017.43
8.1.50.0040.00417.45
8.1.40.0050.00317.34
8.1.30.0000.00817.46
8.1.20.0040.00417.55
8.1.10.0040.00417.37
8.1.00.0040.00417.30
8.0.300.0070.00018.77
8.0.290.0040.00416.63
8.0.280.0030.00318.16
8.0.270.0030.00617.16
8.0.260.0000.00617.21
8.0.250.0000.00716.86
8.0.240.0000.00716.79
8.0.230.0030.00316.89
8.0.220.0000.00716.74
8.0.210.0000.00716.70
8.0.200.0040.00416.80
8.0.190.0030.00616.75
8.0.180.0040.00416.88
8.0.170.0000.00816.88
8.0.160.0000.00816.81
8.0.150.0000.00716.76
8.0.140.0100.00016.83
8.0.130.0030.00313.35
8.0.120.0000.00716.87
8.0.110.0050.00316.87
8.0.100.0080.00016.93
8.0.90.0040.00416.84
8.0.80.0130.00316.88
8.0.70.0040.00416.83
8.0.60.0070.00016.87
8.0.50.0000.00716.91
8.0.30.0070.01217.08
8.0.20.0110.01017.40
8.0.10.0060.00316.88
8.0.00.0090.00816.74
7.4.330.0030.00315.00
7.4.320.0030.00316.52
7.4.300.0000.00716.50
7.4.290.0040.00416.57
7.4.280.0050.00516.50
7.4.270.0030.00316.52
7.4.260.0030.00316.54
7.4.250.0040.00416.34
7.4.240.0040.00316.36
7.4.230.0060.00016.52
7.4.220.0040.01416.50
7.4.210.0060.00916.61
7.4.200.0000.00716.52
7.4.160.0100.01316.50
7.4.150.0110.00817.40
7.4.140.0080.01017.86
7.4.130.0080.00816.45
7.4.120.0130.00616.45
7.4.110.0080.00816.29
7.4.100.0100.00616.55
7.4.90.0100.00716.50
7.4.80.0040.01318.80
7.4.70.0030.01316.43
7.4.60.0090.01216.50
7.4.50.0030.00616.26
7.4.40.0030.01316.39
7.4.30.0060.00916.57
7.4.00.0020.01515.03
7.3.330.0060.00013.18
7.3.320.0020.00213.38
7.3.310.0000.00716.13
7.3.300.0000.00716.36
7.3.290.0080.00816.36
7.3.280.0080.01216.34
7.3.270.0060.01117.40
7.3.260.0070.01616.48
7.3.250.0110.00916.37
7.3.240.0070.01116.57
7.3.230.0130.00616.48
7.3.210.0080.00816.41
7.3.200.0040.01419.39
7.3.190.0040.01416.54
7.3.180.0070.01016.36
7.3.170.0110.00616.55
7.3.160.0060.01016.48
7.3.120.0070.01114.77
7.3.110.0070.01114.68
7.3.100.0000.01714.75
7.3.90.0030.01014.82
7.3.80.0030.01215.07
7.3.70.0030.00714.93
7.3.60.0070.00714.58
7.3.50.0130.00014.76
7.3.40.0070.00714.61
7.3.30.0000.01114.86
7.3.20.0070.00716.81
7.3.10.0100.00416.57
7.3.00.0040.00716.73
7.2.330.0140.00316.64
7.2.320.0060.01116.63
7.2.310.0070.01016.68
7.2.300.0060.01516.43
7.2.290.0080.00816.61
7.2.250.0030.01614.78
7.2.240.0070.01315.27
7.2.230.0070.01015.14
7.2.220.0090.00915.18
7.2.210.0090.00914.71
7.2.200.0140.00015.04
7.2.190.0060.00315.12
7.2.180.0060.00815.10
7.2.170.0030.01014.93
7.2.130.0100.00316.85
7.2.120.0040.01116.98
7.2.110.0070.00716.93
7.2.100.0040.01116.65
7.2.90.0060.00316.99
7.2.80.0100.00016.83
7.2.70.0100.00616.97
7.2.60.0060.00916.68
7.2.50.0060.00616.96
7.2.40.0100.00716.96
7.2.30.0100.00016.91
7.2.20.0080.00416.86
7.2.10.0060.00816.94
7.2.00.0070.00317.00
7.1.330.0060.00915.58
7.1.320.0060.00615.62
7.1.310.0100.00315.86
7.1.300.0100.00315.60
7.1.290.0080.00815.76
7.1.280.0030.00615.64
7.1.270.0060.00615.34
7.1.260.0030.01315.65
7.1.250.0000.01215.82
7.1.70.0000.01117.27
7.1.60.0140.01119.32
7.1.50.0130.01016.85
7.1.00.0100.06722.57
7.0.200.0000.00816.67
7.0.140.0070.06722.04
7.0.60.0030.08320.09
7.0.50.0100.08017.90
7.0.40.0030.04720.27
7.0.30.0300.08320.14
7.0.20.0330.07720.09
7.0.10.0030.08720.05
7.0.00.0170.07320.33
5.6.280.0000.07720.91
5.6.210.0030.04720.61
5.6.200.0100.05318.16
5.6.190.0070.05720.61
5.6.180.0100.07720.34
5.6.170.0270.07720.54
5.6.160.0070.06720.46
5.6.150.0030.06718.22
5.6.140.0070.07318.28
5.6.130.0130.07318.19
5.6.120.0130.07721.05
5.6.110.0070.04321.16
5.6.100.0100.05721.04
5.6.90.0070.07320.88
5.6.80.0100.07720.38
5.5.350.0170.03720.53
5.5.340.0070.04017.96
5.5.330.0030.04320.43
5.5.320.0100.05720.20
5.5.310.0370.07720.30
5.5.300.0000.06317.98
5.5.290.0200.03717.92
5.5.280.0030.08020.98
5.5.270.0000.04720.73
5.5.260.0030.07320.84
5.5.250.0070.05720.70
5.5.240.0230.07020.27
5.4.450.0300.05719.27
5.4.440.0100.06319.69
5.4.430.0270.04319.44
5.4.420.0670.00019.51
5.4.410.0630.00019.52
5.4.400.0630.00019.38
5.4.390.0630.00019.02
5.4.380.0330.06318.80
5.4.370.0330.05318.51
5.4.360.0200.06318.62
5.4.350.0430.05018.84
5.4.340.0430.04718.80
5.4.320.0070.03412.51
5.4.310.0070.03912.50
5.4.300.0050.03712.51
5.4.290.0070.03612.50
5.4.280.0090.03212.40
5.4.270.0060.03612.40
5.4.260.0050.03812.40
5.4.250.0080.03512.39
5.4.240.0060.03512.40
5.4.230.0050.03812.39
5.4.220.0020.03912.39
5.4.210.0070.03312.39
5.4.200.0010.04112.39
5.4.190.0040.03712.39
5.4.180.0070.03412.39
5.4.170.0030.03812.39
5.4.160.0060.03512.39
5.4.150.0090.03212.38
5.4.140.0060.03612.07
5.4.130.0040.03712.06
5.4.120.0090.04212.02
5.4.110.0060.03612.01
5.4.100.0040.03712.02
5.4.90.0060.03612.01
5.4.80.0090.03412.01
5.4.70.0080.03212.00
5.4.60.0030.03812.00
5.4.50.0050.03712.01
5.4.40.0060.03511.99
5.4.30.0040.03611.99
5.4.20.0050.03711.99
5.4.10.0060.03611.99
5.4.00.0080.03611.48
5.3.290.0090.03912.80
5.3.280.0070.03712.71
5.3.270.0030.04312.72
5.3.260.0100.03512.72
5.3.250.0060.03712.72
5.3.240.0060.03612.72
5.3.230.0070.03712.71
5.3.220.0060.04112.68
5.3.210.0070.03812.68
5.3.200.0060.04112.68
5.3.190.0070.04412.67
5.3.180.0070.03612.67
5.3.170.0070.03512.67
5.3.160.0040.04212.68
5.3.150.0080.04812.67
5.3.140.0080.03812.66
5.3.130.0080.05112.66
5.3.120.0060.04212.66
5.3.110.0070.04112.66
5.3.100.0050.03712.12
5.3.90.0060.03812.10
5.3.80.0080.03612.09
5.3.70.0080.03512.09
5.3.60.0070.03612.07
5.3.50.0070.03512.02
5.3.40.0050.03812.02
5.3.30.0060.03411.98
5.3.20.0050.03811.77
5.3.10.0070.03411.73
5.3.00.0040.03911.72
5.2.170.0070.0299.23
5.2.160.0050.0299.23
5.2.150.0060.0309.23
5.2.140.0060.0299.23
5.2.130.0040.0309.18
5.2.120.0020.0309.19
5.2.110.0050.0289.20
5.2.100.0050.0289.19
5.2.90.0040.0329.19
5.2.80.0070.0299.19
5.2.70.0060.0299.18
5.2.60.0040.0309.14
5.2.50.0040.0319.11
5.2.40.0050.0289.09
5.2.30.0050.0299.06
5.2.20.0080.0259.05
5.2.10.0060.0268.95
5.2.00.0020.0308.82
5.1.60.0050.0228.11
5.1.50.0040.0248.10
5.1.40.0040.0278.08
5.1.30.0010.0298.43
5.1.20.0070.0278.45
5.1.10.0040.0268.18
5.1.00.0070.0228.18
5.0.50.0030.0216.66
5.0.40.0050.0176.52
5.0.30.0020.0326.33
5.0.20.0020.0206.30
5.0.10.0030.0206.27
5.0.00.0080.0276.27
4.4.90.0020.0164.78
4.4.80.0040.0144.75
4.4.70.0030.0164.75
4.4.60.0030.0164.75
4.4.50.0030.0184.77
4.4.40.0050.0274.71
4.4.30.0030.0154.76
4.4.20.0050.0144.84
4.4.10.0040.0144.85
4.4.00.0020.0254.76
4.3.110.0020.0164.67
4.3.100.0040.0134.67
4.3.90.0030.0144.63
4.3.80.0040.0224.59
4.3.70.0010.0184.63
4.3.60.0030.0144.63
4.3.50.0010.0174.63
4.3.40.0020.0254.54
4.3.30.0000.0183.33
4.3.20.0010.0173.30
4.3.10.0020.0153.26
4.3.00.0000.04016.39

preferences:
40.56 ms | 401 KiB | 5 Q