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 40 41 42 43 44 45
|
<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function showTimeExec($timeStart,$msg)
{
$time_end = microtime_float();
$time_exec = $time_end - $timeStart ;
echo " $msg : <strong> $time_exec </strong> <br />\n";
}
//remplissage du tableau
$array = array();
for ($i=0; $i < 9000 ; $i++) {
$array[] = $i;
}
//test for
$timeStart1 = microtime_float() ;
$count = count($array);
for ($i=0; $i<$count; $i++)
{
echo $array[$i] .' ; ';
}
showTimeExec($timeStart1, ' temps d\'execution boucle for');
//test foreach
$timeStart2 = microtime_float() ;
foreach ($array as $v) {
echo $v .' ; ' ;
}
showTimeExec($timeStart2, ' temps d\'execution boucle foreach');
?> |