3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = ['1613938511.464898123456789', '1613938511.464898923456789', '1613938511.123456789', '1613938511.12345678910', '1613938519.123456789', '1613938511.999999', '1613938511.999999999999']; foreach ($tests as $test) { echo "Testing : $test\n"; $f = (float)$test; // echo " string=" . $f . " | json =" . json_encode($f); $jsonOne = substr(json_encode($f),0,17); $testOne = substr($test,0,17); echo "\n> Test passed :" . $jsonOne ." =?= ". $testOne . " ::: " . ($jsonOne === $testOne ? 'yes' : 'no'); echo "\n-------------------------------------------------\n"; } // more complex testing $test1MResults = []; $testFailed = []; for ($i = 0; $i < 1000000; $i++) { $testFloat = '1613938511.' . $i; $floatN = (float) $testFloat; $jsonN = json_encode($floatN); $floatJsonN = (float) $jsonN; $absN = (int) abs($floatN - $floatJsonN) * 1000000; /** * Why using or when compare text faild ? because json delete the zero at end of a float , but in our testFloat its composed string 'xx'.$i (10) * Why using int comparasion ? to strict verify that $floatN === $floatJsonN with the 6 digits * * You can play with conditions to see example of fails (that are not really a fail but just a wrong comparasion method) */ $passed = ($jsonN === $testFloat || $absN === 0); $test1MResults[] = $passed; if (false === $passed) { $testFailed[] = [$i, $jsonN, $testFloat, $absN, gettype($absN)]; } } $totalTests = count($test1MResults); $totalSuccess = count(array_filter($test1MResults)); $totalFails = $totalTests - $totalSuccess; print_r("Total Success : " . $totalSuccess . "\n"); print_r("Total Fails : " . ($totalFails) . "\n"); if ($totalFails > 0) { $maxShow = 10 > $totalFails ? $totalFails : 10; for ($i=0; $i < $maxShow; $i++) { print_r(json_encode($testFailed[$i])); echo "\n"; } for ($i=$totalFails; $i > $totalFails - $maxShow; $i--) { print_r(json_encode($testFailed[$i])); echo "\n"; } } echo "\n\n"; /** * Total Success : 1000000 * Total Fails : 0 */

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.0701.22349.51
8.3.50.0631.55649.44
8.3.40.0401.23743.14
8.3.30.0431.29043.16
8.3.20.0200.64245.97
8.3.10.0100.62746.96
8.3.00.0100.64444.89
8.2.180.0371.17949.70
8.2.170.0501.17943.09
8.2.160.0271.26144.52
8.2.150.0170.65044.55
8.2.140.0230.63444.67
8.2.130.0370.62544.69
8.2.120.0170.63745.02
8.1.280.1071.23566.01
8.1.270.0170.35839.91
8.1.260.0130.33334.77
8.1.250.0070.33641.95
8.0.30.0831.80064.33
8.0.20.0791.84964.37
8.0.10.0951.79957.16
8.0.00.0741.78564.45
7.4.160.0811.82856.85
7.4.150.0731.73763.92
7.4.140.0851.75163.93
7.4.130.0921.72763.94
7.4.120.0871.83263.96
7.4.110.0921.84364.05
7.4.100.0961.74064.02
7.4.90.0711.69463.96
7.4.80.0731.67763.99
7.4.70.0721.72163.93
7.4.60.0751.80163.91
7.4.50.0841.72756.63
7.4.40.0661.89463.91
7.4.30.0631.93350.18
7.4.20.0831.87056.68
7.4.10.0991.90854.34
7.4.00.0751.88156.62
7.3.270.0731.80763.72
7.3.260.0851.75163.86
7.3.250.0811.81663.82
7.3.240.0811.66563.79
7.3.230.0621.82663.76
7.3.220.0671.82156.42
7.3.210.0631.68163.71
7.3.200.0791.72663.71
7.3.190.0831.73363.73
7.3.180.0721.78463.69
7.3.170.0761.75463.78
7.3.160.0841.82263.70
7.3.150.0581.88356.49
7.3.140.0711.92849.18
7.3.130.0791.84063.66
7.3.120.0891.82463.66
7.3.110.0831.86456.33
7.3.100.0711.92763.66
7.3.90.0811.92156.71
7.3.80.0631.84656.53
7.3.70.0681.78463.86
7.3.60.0771.82256.57
7.3.50.0661.77763.78
7.3.40.0841.79656.60
7.3.30.0761.89663.80
7.3.20.0871.83956.61
7.3.10.1131.72063.84
7.3.00.1281.74263.95
7.2.340.0701.88956.62
7.2.330.0731.88556.59
7.2.320.0911.90063.87
7.2.310.0721.82863.88
7.2.300.0841.85663.91
7.2.290.0651.90861.23
7.2.280.0681.91450.50
7.2.270.0841.87863.85
7.2.260.0631.92149.35
7.2.250.0581.93649.38
7.2.240.0681.94249.32
7.2.230.0881.90856.61
7.2.220.0771.91849.40
7.2.210.0551.95849.32
7.2.200.0661.93156.79
7.2.190.0891.88156.72
7.2.180.0541.94449.53
7.2.170.0861.92456.83
7.2.160.0801.87756.81
7.2.150.1191.82056.85
7.2.140.1091.81564.15
7.2.130.1121.85358.25
7.2.120.1091.78464.16
7.2.110.1191.80356.99
7.2.100.0981.81556.84
7.2.90.1371.84957.29
7.2.80.1021.89053.87
7.2.70.0941.89856.78
7.2.60.0951.86856.88
7.2.50.1111.81257.25
7.2.40.1011.85857.28
7.2.30.1241.85964.18
7.2.20.1191.78564.56
7.2.10.1151.78865.31
7.2.00.1011.82156.86
7.1.330.0771.91748.62
7.1.320.0881.90948.56
7.1.310.0821.88755.89
7.1.300.0901.89748.54
7.1.290.1061.88155.80
7.1.280.0841.91448.49
7.1.270.1131.84163.09
7.1.260.0911.88055.84
7.1.250.1091.89548.45
7.1.240.0931.90752.74
7.1.230.1271.85055.87
7.1.220.1251.85655.83
7.1.210.1021.86055.71
7.1.200.0861.91753.43
7.1.190.1151.81263.06
7.1.180.0781.83756.07
7.1.170.0931.88356.14
7.1.160.0891.90556.49
7.1.150.0931.91060.95
7.1.140.1041.82756.06
7.1.130.1261.76663.72
7.1.120.1041.89754.30
7.1.110.0941.89355.71
7.1.100.0871.89755.74
7.1.90.1031.83457.54
7.1.80.1081.87449.23
7.1.70.0751.91548.81
7.1.60.1221.85355.80
7.1.50.1341.84855.82
7.1.40.0841.89755.73
7.1.30.0731.92949.04
7.1.20.0851.90849.23
7.1.10.0891.91149.28
7.1.00.0981.86949.55
7.0.330.1241.06962.71
7.0.320.1070.98462.78
7.0.310.1351.03463.21
7.0.300.0971.01162.79
7.0.290.1241.05462.79
7.0.280.1140.98663.21
7.0.270.1090.95163.54
7.0.260.0940.97762.87
7.0.250.1021.00063.29
7.0.240.0911.06163.68
7.0.230.0871.01463.58
7.0.220.1341.02763.23
7.0.210.1080.95263.62
7.0.200.1011.00962.88
7.0.190.0991.05662.85
7.0.180.1071.08863.56
7.0.170.1391.07563.65
7.0.160.1340.99663.50
7.0.150.1061.00763.53
7.0.140.1061.02163.52
7.0.130.1111.02163.23
7.0.120.1041.01563.19
7.0.110.1111.05663.20
7.0.100.1151.01955.95
7.0.90.0911.10362.84
7.0.80.0861.08463.16
7.0.70.1181.17263.05
7.0.60.1051.18063.24
7.0.50.1301.23463.10
7.0.40.1521.23162.80
7.0.30.1161.01062.81
7.0.20.0961.03062.82
7.0.10.2010.97562.79
7.0.00.1041.09262.78
5.6.400.0760.80580.48
5.6.390.0720.78580.55
5.6.380.0670.82580.53
5.6.370.1041.03280.54
5.6.360.0730.95380.50
5.6.350.0840.87180.58
5.6.340.0610.83780.61
5.6.330.0950.93580.53
5.6.320.0620.92980.57
5.6.310.0660.78880.51
5.6.300.0851.09680.46
5.6.290.0670.86480.59
5.6.280.0830.90180.57
5.6.270.0630.96680.57
5.6.260.0770.88780.53
5.6.250.0940.89380.55
5.6.240.0560.91980.63
5.6.230.0940.78080.71
5.6.220.1180.81280.71
5.6.210.0600.91980.75
5.6.200.0560.96680.89
5.6.190.0630.91080.77
5.6.180.0760.85280.65
5.6.170.0751.06880.71
5.6.160.0690.77980.85
5.6.150.0990.83280.82
5.6.140.0600.79880.66
5.6.130.0800.78780.69
5.6.120.0650.84280.71
5.6.110.0690.79680.76
5.6.100.0820.99880.66
5.6.90.0790.77080.54
5.6.80.0680.78480.43
5.6.70.0570.80680.61
5.6.60.0540.80180.52
5.6.50.0720.94180.59
5.6.40.0741.02480.68
5.6.30.0620.90480.63
5.6.20.0940.90380.65
5.6.10.0541.00280.60
5.6.00.0880.90280.53
5.5.380.0830.95380.72
5.5.370.0521.01980.80
5.5.360.0861.04180.57
5.5.350.0630.90280.53
5.5.340.0901.01080.44
5.5.330.0700.90880.57
5.5.320.0690.98080.54
5.5.310.0881.03380.61
5.5.300.0850.96280.56
5.5.290.0760.93280.49
5.5.280.0820.94880.50
5.5.270.0770.87180.67
5.5.260.0740.97180.72
5.5.250.0730.92780.75
5.5.240.0911.08480.72
5.5.230.0710.93780.77
5.5.220.0630.94280.73
5.5.210.0670.94080.71
5.5.200.0991.00880.49
5.5.190.0830.95580.44
5.5.180.0641.20280.39
5.5.170.0731.02480.58
5.5.160.0731.07880.45
5.5.150.0871.24180.40
5.5.140.0740.94180.44
5.5.130.0711.04180.43
5.5.120.0640.92780.46
5.5.110.0920.97680.31
5.5.100.0721.00880.62
5.5.90.0560.99580.68
5.5.80.0881.12680.63
5.5.70.0711.08480.52
5.5.60.0601.00380.55
5.5.50.0890.97580.58
5.5.40.0760.94680.46
5.5.30.0781.01180.50
5.5.20.0771.29380.60
5.5.10.0721.01380.41
5.5.00.0590.98080.58
5.4.450.0621.00377.35
5.4.440.0580.88277.35
5.4.430.0660.92277.29
5.4.420.0850.98277.30
5.4.410.0600.87577.30
5.4.400.0850.98277.29
5.4.390.0750.84077.28
5.4.380.0850.93077.36
5.4.370.0530.93377.23
5.4.360.0801.00977.28
5.4.350.0710.99877.26
5.4.340.0830.98377.31
5.4.330.0730.99477.35
5.4.320.0741.11477.35
5.4.310.0730.91977.31
5.4.300.0711.02477.35
5.4.290.0891.00377.35
5.4.280.0621.00677.31
5.4.270.0691.12977.41
5.4.260.1041.05277.24
5.4.250.0560.93377.26
5.4.240.0740.88677.22
5.4.230.0851.12177.01
5.4.220.0891.09277.02
5.4.210.0840.97177.01
5.4.200.0741.03577.01
5.4.190.0740.92777.01
5.4.180.0841.03777.09
5.4.170.0540.99077.11
5.4.160.0681.06777.06
5.4.150.0740.97277.03
5.4.140.0891.08477.25
5.4.130.0580.96277.29
5.4.120.0720.99477.35
5.4.110.0830.95377.30
5.4.100.0851.07477.32
5.4.90.0661.05677.31
5.4.80.0750.89577.40
5.4.70.0621.06777.40
5.4.60.0601.04677.41
5.4.50.0560.92377.22
5.4.40.0741.01177.32
5.4.30.0710.98877.36
5.4.20.0931.03877.34
5.4.10.0900.96377.36
5.4.00.0870.92477.15
5.3.290.0080.01112.84
5.3.280.0090.00612.66
5.3.270.0050.01012.65
5.3.260.0100.00512.82
5.3.250.0020.01512.68
5.3.240.0100.00512.68
5.3.230.0100.00512.68
5.3.220.0100.00712.60
5.3.210.0030.01312.57
5.3.200.0110.00512.64
5.3.190.0090.00712.75
5.3.180.0090.00812.81
5.3.170.0070.01012.74
5.3.160.0070.00912.83
5.3.150.0060.00912.83
5.3.140.0080.00812.75
5.3.130.0050.01012.86
5.3.120.0100.00812.87
5.3.110.0080.00812.77
5.3.100.0080.00812.83
5.3.90.0080.00912.71
5.3.80.0100.00812.62
5.3.70.0060.01112.72
5.3.60.0070.00712.83
5.3.50.0070.00812.75
5.3.40.0060.01112.70
5.3.30.0090.00612.75
5.3.20.0130.00312.62
5.3.10.0120.00512.42
5.3.00.0060.01112.48
5.2.170.0090.00311.83
5.2.160.0050.00811.73
5.2.150.0060.00611.87
5.2.140.0040.01011.68
5.2.130.0060.00911.73
5.2.120.0090.00611.73
5.2.110.0100.00411.69
5.2.100.0070.00811.70
5.2.90.0060.00811.74
5.2.80.0170.00611.71
5.2.70.0100.00511.68
5.2.60.0050.00911.61
5.2.50.0120.00311.74
5.2.40.0060.00911.69
5.2.30.0060.00711.78
5.2.20.0080.00611.43
5.2.10.0070.00711.42
5.2.00.0070.00811.43
5.1.60.0050.00811.26
5.1.50.0040.00811.26
5.1.40.0040.00711.26
5.1.30.0070.00711.26
5.1.20.0070.00811.26
5.1.10.0070.00711.26
5.1.00.0060.00711.26
5.0.50.0080.00311.26
5.0.40.0070.00311.26
5.0.30.0040.00711.26
5.0.20.0060.00511.26
5.0.10.0050.00711.26
5.0.00.0060.00611.26
4.4.90.0040.00311.26
4.4.80.0030.00411.26
4.4.70.0030.00311.26
4.4.60.0020.00311.26
4.4.50.0030.00311.26
4.4.40.0060.00011.26
4.4.30.0020.00411.26
4.4.20.0020.00511.26
4.4.10.0020.00511.26
4.4.00.0020.00511.26
4.3.110.0040.00211.26
4.3.100.0010.00511.26
4.3.90.0030.00311.26
4.3.80.0060.00311.26
4.3.70.0060.00211.26
4.3.60.0050.00211.26
4.3.50.0040.00511.26
4.3.40.0000.00811.26
4.3.30.0000.00811.26
4.3.20.0050.00211.26
4.3.10.0030.00311.26
4.3.00.0000.00511.26

preferences:
46.39 ms | 401 KiB | 5 Q