We often need to do the execution time execution efficiency judgment of the program.
The following ideas are implemented:
<?php
//记录开始时间
//记录结整时
// 开始时间 减去(-) 结束时间 得到程序的运行时间
?>
But let's not forget that the program is running too fast. It's just 0.00000 seconds to the flash. At this point, we're going to write a function of a special letter:
Mixed Microtime ([bool $get _as_float])
The Microtime () function, which returns the current Unix timestamp and the number of microseconds.
Parameters:
If you pass in true, it will return a floating-point type of time, so that it is convenient to participate in the operation.
Let's simulate an example that detects the execution time of a function and tests how quickly a function is efficient:
<?php
//开始时间
$time_start = microtime(true);
//循环一万次
for($i = 0 ; $i < 10000 ; $i++){
//你可以用上,mktime() 生成一个昨天的时间
//再用strtotime() 生成一个昨天的时间
//对比两个函数认的效率高
}
//结整时间
$time_end = microtime(true);
//相减得到运行时间
$time = $time_end - $time_start;
echo "这个脚本执行的时间为 $time seconds\n";
?>
From for notes (Wiz)
Front-End PHP entry -023-program execution time detection for key date functions