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
|
<?php
$str = "watch?v=DANqhe10v4k&feature";
for ($j=1; $j<5; $j++) {
$reg = '/v=([^&]++)&/';
$found = 0;
$start = microtime(true);
for ($i=1; $i<100000; $i++) if (preg_match($reg, $str, $match)) $found ++;
$end = microtime(true);
printf ("Temps 1 = %0.2f pour %d matchings\n", $end-$start, $found);
$reg = '/(?<=v=)[^&]*/';
$found = 0;
$start = microtime(true);
for ($i=1; $i<100000; $i++) if (preg_match($reg, $str, $match)) $found ++;
$end = microtime(true);
printf ("Temps 2 = %0.2f pour %d matchings\n", $end-$start, $found);
}
/* Affichage sur ma machine
Temps 1 = 0.90 pour 99999 matchings
Temps 2 = 0.97 pour 99999 matchings
Temps 1 = 0.94 pour 99999 matchings
Temps 2 = 0.97 pour 99999 matchings
Temps 1 = 0.88 pour 99999 matchings
Temps 2 = 0.97 pour 99999 matchings
Temps 1 = 0.89 pour 99999 matchings
Temps 2 = 0.95 pour 99999 matchings
*/ |
Partager