ikuwow
4/4/2016 - 7:16 AM

ctype_digit_vs_preg_match.php

<?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";