Help, calculate code run time
$sTime =microtime ();
$arr =array (1,2,3,4);
foreach ($arr as $a) {
echo $a. '
';
}
$eTime =microtime ();
Echo $sTime;
Echo $eTime;
$title =floatval ($sTime-$eTime);
echo $title;
PHP
Share to: more
------Solution--------------------
$sTime = Microtime ( true);
This is the number of floating-point numbers that can be calculated
Echo Microtime (True)-$_server["Request_time_float"];
To know the time it takes to start responding to the current moment from PHP
------Solution--------------------
$sTime =microtime (TRUE);
$arr =array (1,2,3,4);
for ($i =0; $i <=10000; $i + +) {
echo $i. '
';
}
foreach ($arr as $a) {
echo $a. '
';
// }
$eTime =microtime (TRUE);
echo $sTime, Echo '
';
echo $eTime, Echo '
';
$title =floatval ($eTime-$sTime);
echo $title; Your array is too small, I changed the next can easily see the program run time, with
$sTime =microtime (TRUE);
$arr =array (1,2,3,4);
for ($i =0; $i <=10000; $i + +) {
echo $i. '
';
// }
foreach ($arr as $a) {
echo $a. '
';
}
$eTime =microtime (TRUE);
echo $sTime, Echo '
';
echo $eTime, Echo '
';
$title =floatval ($eTime-$sTime);
echo $title; yes, it is.