@ 2018-10-10T09:11:50Z <?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";
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
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).
Version System time (s) User time (s) Memory (MiB) 7.2.11 0.118 0.213 14.98 7.2.10 0.013 0.180 14.66 7.2.9 0.107 0.221 14.64 7.2.8 0.046 0.236 14.63 7.2.7 0.022 0.248 14.73 7.2.6 0.178 0.281 14.88 7.2.5 0.010 0.241 15.27 7.2.4 0.013 0.348 14.95 7.2.3 0.269 0.230 14.76 7.2.2 0.017 0.180 14.84 7.2.1 0.060 0.292 15.00 7.2.0 0.029 0.279 14.91 7.1.23 0.063 0.302 13.93 7.1.22 0.041 0.265 13.80 7.1.21 0.010 0.270 14.03 7.1.20 0.042 0.240 13.72 7.1.19 0.052 0.268 13.90 7.1.18 0.026 0.243 13.81 7.1.17 0.006 0.251 13.54 7.1.16 0.109 0.245 13.68 7.1.15 0.036 0.340 13.88 7.1.14 0.227 0.253 13.87 7.1.13 0.049 0.270 13.87 7.1.12 0.019 0.290 13.56 7.1.11 0.013 0.453 13.91 7.1.10 0.182 0.274 13.97 7.1.9 0.068 0.334 13.65 7.1.8 0.182 0.275 13.49 7.1.7 0.013 0.249 13.93 7.1.6 0.045 0.225 31.61 7.1.5 0.091 0.248 31.76 7.1.4 0.813 0.222 31.48 7.1.3 0.039 0.240 31.80 7.1.2 0.023 0.307 31.75 7.1.1 0.174 0.241 13.52 7.1.0 0.191 0.331 13.52 5.6.38 0.012 0.579 14.14
preferences:dark mode live preview
37.75 ms | 400 KiB | 5 Q