PHP program exe...LOGIN

PHP program execution time detection

We sometimes need to judge the execution time and execution efficiency of the program.

The implementation ideas are as follows:

<?php
//记录开始时间



//记录结整时


// 开始时间  减去(-)  结束时间  得到程序的运行时间

?>

But don’t forget that the program runs too fast. It's as fast as a moment of only 0.00000 seconds. At this time, everyone has to record a special function:

mixed microtime ([ bool $get_as_float ] )

microtime() This function can return the current Unix timestamp and microseconds.

Parameters:
If you pass in true, a floating point type time will be returned, which is convenient for participating in operations.

Let’s simulate an example of detecting the execution time of a function to test the efficiency of a certain function:

<?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";
?>

The final output result is the execution time of our actual function. You can compare several times to see the final result.

Whoever has less time can use which function frequently in actual work.


Next Section
<?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"; ?>
submitReset Code
ChapterCourseware