3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); $n = "5281"; // checking the first byte is enough //---------------------------------------------------------------------------------------- $st = microtime(TRUE); for($i = 0; $i < 1000000; $i++){ $x = is_numeric($n); } echo number_format(microtime(TRUE) - $st, 10) . "\n"; //---------------------------------------------------------------------------------------- $st = microtime(TRUE); for($i = 0; $i < 1000000; $i++){ $x = is_numeric($n[0]); // check only the first byte - makes it a bit slower tho } echo number_format(microtime(TRUE) - $st, 10) . "\n"; //---------------------------------------------------------------------------------------- $digits = [ 0 => TRUE, 1 => TRUE, 2 => TRUE, 3 => TRUE, 4 => TRUE, 5 => TRUE, 6 => TRUE, 7 => TRUE, 8 => TRUE, 9 => TRUE ]; $st = microtime(TRUE); for($i = 0; $i < 1000000; $i++){ $x = isset($digits[$n[0]]); // fastest solution } echo number_format(microtime(TRUE) - $st, 10) . "\n"; //---------------------------------------------------------------------------------------- $st = microtime(TRUE); for($i = 0; $i < 1000000; $i++){ $x = (String)(Int)$n[0] === $n[0]; // slowest solution } echo number_format(microtime(TRUE) - $st, 10) . "\n";

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.2.110.1180.21314.98
7.2.100.0130.18014.66
7.2.90.1070.22114.64
7.2.80.0460.23614.63
7.2.70.0220.24814.73
7.2.60.1780.28114.88
7.2.50.0100.24115.27
7.2.40.0130.34814.95
7.2.30.2690.23014.76
7.2.20.0170.18014.84
7.2.10.0600.29215.00
7.2.00.0290.27914.91
7.1.230.0630.30213.93
7.1.220.0410.26513.80
7.1.210.0100.27014.03
7.1.200.0420.24013.72
7.1.190.0520.26813.90
7.1.180.0260.24313.81
7.1.170.0060.25113.54
7.1.160.1090.24513.68
7.1.150.0360.34013.88
7.1.140.2270.25313.87
7.1.130.0490.27013.87
7.1.120.0190.29013.56
7.1.110.0130.45313.91
7.1.100.1820.27413.97
7.1.90.0680.33413.65
7.1.80.1820.27513.49
7.1.70.0130.24913.93
7.1.60.0450.22531.61
7.1.50.0910.24831.76
7.1.40.8130.22231.48
7.1.30.0390.24031.80
7.1.20.0230.30731.75
7.1.10.1740.24113.52
7.1.00.1910.33113.52
5.6.380.0120.57914.14

preferences:
37.75 ms | 400 KiB | 5 Q