php records code execution time

  • 2020-07-21 07:06:11
  • OfStack


$t1 = microtime(true);
// ...  Execute the code  ...
$t2 = microtime(true);
echo ' Time consuming '.round($t2-$t1,3).' seconds ';

If microtime() takes an true argument, it returns a floating-point type. So t1 and t2 get two floating-point Numbers, and the difference between them is the difference. Since the number of digits in the floating-point number is long, or uncertain, an round() is used to pick up three decimal places

Related articles: