<?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";
- Output for 7.2.11
- 0.0425710678
0.0537748337
0.0408380032
0.0978660583
- Output for 7.2.10
- 0.0471370220
0.0580708981
0.0546278954
0.0740480423
- Output for 7.2.9
- 0.0576469898
0.0472950935
0.0391309261
0.0742149353
- Output for 7.2.8
- 0.0369768143
0.0390970707
0.0329811573
0.1401009560
- Output for 7.2.7
- 0.0745518208
0.0723350048
0.0610809326
0.1687948704
- Output for 7.2.6
- 0.0612699986
0.0648500919
0.0641849041
0.1024589539
- Output for 7.2.5
- 0.0661420822
0.0428290367
0.0490570068
0.1320278645
- Output for 7.2.4
- 0.0695121288
0.0759010315
0.0663371086
0.1509680748
- Output for 7.2.3
- 0.0693240166
0.0712301731
0.0417840481
0.0868208408
- Output for 7.2.2
- 0.0527751446
0.0384259224
0.0320770741
0.0669069290
- Output for 7.2.1
- 0.0442001820
0.0866911411
0.0501978397
0.1289720535
- Output for 7.2.0
- 0.0558681488
0.0658879280
0.0501389503
0.1068720818
- Output for 7.1.23
- 0.1651659012
0.1255791187
0.0605220795
0.2098770142
- Output for 7.1.22
- 0.0926079750
0.0486230850
0.0440208912
0.1425039768
- Output for 7.1.21
- 0.0420291424
0.1059238911
0.0704560280
0.1925098896
- Output for 7.1.20
- 0.0534679890
0.0526409149
0.0448698997
0.1023781300
- Output for 7.1.19
- 0.0401959419
0.0659711361
0.0404458046
0.1354439259
- Output for 7.1.18
- 0.0518839359
0.0537629128
0.0446760654
0.1111910343
- Output for 7.1.17
- 0.0456120968
0.0474619865
0.0591690540
0.1228120327
- Output for 7.1.16
- 0.0512468815
0.0463929176
0.0489470959
0.1472220421
- Output for 7.1.15
- 0.0506179333
0.0935409069
0.0680770874
0.1456000805
- Output for 7.1.14
- 0.0810198784
0.0482079983
0.0538749695
0.0980010033
- Output for 7.1.13
- 0.0691709518
0.0498328209
0.0518000126
0.1545550823
- Output for 7.1.12
- 0.0709831715
0.0686528683
0.0386450291
0.1354160309
- Output for 7.1.11
- 0.0955891609
0.1045639515
0.0751371384
0.2185959816
- Output for 7.1.10
- 0.0436530113
0.0627059937
0.0411541462
0.1585669518
- Output for 7.1.9
- 0.1040079594
0.0922529697
0.0565359592
0.1259889603
- Output for 7.1.8
- 0.0452001095
0.0591049194
0.0419399738
0.1553230286
- Output for 7.1.7
- 0.0441210270
0.0480980873
0.0382490158
0.1151769161
- Output for 7.1.6
- 0.0836651325
0.0441291332
0.0409309864
0.0909721851
- Output for 7.1.5
- 0.0670080185
0.0497519970
0.0346131325
0.1345188618
- Output for 7.1.4
- 0.0571939945
0.0591228008
0.0346679688
0.0846650600
- Output for 7.1.3
- 0.0401849747
0.0498540401
0.0343508720
0.1411998272
- Output for 7.1.2
- 0.0657250881
0.1120631695
0.0435461998
0.1096620560
- Output for 7.1.1
- 0.0416660309
0.0518560410
0.0408999920
0.1030328274
- Output for 7.1.0
- 0.1363220215
0.0915091038
0.0625941753
0.1205267906
- Output for 5.6.38
- Warning: Unsupported declare 'strict_types' in /in/RGKJk on line 1
0.1574451923
0.2287278175
0.1279459000
0.4210197926
preferences:
76.79 ms | 401 KiB | 42 Q