1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
<?php
$str = "aZzer1256666";
$nbTests = 100000;
$start = microtime(true);
for ($i=1; $i<$nbTests; $i++) {
if ( strlen ($str) >= 8 and
preg_match('/[a-z]/', $str) and
preg_match('/[A-Z]/', $str) and
preg_match('/[0-9]/', $str) )
$dummy = "ok";
else
$dummy = "ko";
}
$end = microtime(true);
$time = $end - $start;
echo "t1 = ". $time ."\n";
$start = microtime(true);
for ($i=1; $i<$nbTests; $i++) {
if(preg_match("`^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{8,}$`", $str))
$dummy = "ok";
else
$dummy = "ko";
}
$end = microtime(true);
$time = $end - $start;
echo "t2 = ". $time ."\n";
/* RESULTATS
t1 = 1.0430560112
t2 = 0.49570107460022
*/ |