2

I have a loop with a number of functions

I want to check how long the entire loop runs, and also each of the functions within the loop

Is it possible to use a parent and many child microtime functions simultaneously?

$start = microtime(true);

foreach ($rows as $row) {

  if ($row == "a") {
     $start1 = microtime(true);
     // do function stuff
     $finish1 = microtime(true);
     echo("function 1 took", $finish1 - $start1, "seconds");
  }

  if ($row == "b") {
     $start2 = microtime(true);
     // do function stuff
     $finish2 = microtime(true);
     echo("function 2 took", $finish2 - $start2, "seconds");
  }
}

$finish = microtime(true);

echo("all functions took", $finish - $start, "seconds");
4

1 回答 1

1

通过“父”函数,我假设您的意思是microtimeforeach 循环之外的函数调用。

如果是这种情况,那么是的,每次调用时microtime,它都会返回脚本执行的当前时间戳,而不管之前对microtime.

于 2019-08-23T16:32:55.680 回答