Created
April 4, 2016 07:16
-
-
Save ikuwow/5c223fc72f94d1949cd048ad2492e499 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$input = 'hoge00'; | |
$trials = 100000; | |
$tic = microtime(true); | |
for ($i = 0; $i < $trials; $i++) { | |
preg_match("/^[0-9]+$/", $input); | |
} | |
echo (string)(microtime(true) - $tic) . "\n"; | |
$tic = microtime(true); | |
for ($i = 0; $i < $trials; $i++) { | |
ctype_digit($input); | |
} | |
echo (string)(microtime(true) - $tic) . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this trial,
ctype_digit()
is 3 times faster thanpreg_match()
.