Source: http://www.jb51.net/article/49974.htm
First of all, we analyze the principle, to get the program running time, then you can define a variable at the start of the program to write down the current time, and then after we run the program to record the current time, the difference is that the program to run the time spent.
Here's a microtime () This function, Microtime () not much, but not the function is not known, it is to return the current Unix timestamp and the number of microseconds. For example: Echo Microtime (); will return: 0.08845800 1376983061. So you can use the explode function to divide it into an array of spaces, then the $starttime[0]=0.08845800 (microseconds), $starttime [1]=1376983061 (the current number of seconds, equivalent to time () results).
Sample code:
Copy code code as follows:
<?php
Program Run time
$starttime = Explode (', microtime ());
Echo Microtime ();
/*········ The following is the code area */
For ($i =0 $i <1000000; $i + +) {
$i;
}
/*········ Above is code area */
Program Run time
$endtime = Explode (', microtime ());
$thistime = $endtime [0]+ $endtime [1]-($starttime [0]+ $starttime [1]);
$thistime = Round ($thistime, 3);
echo "This page is time-consuming to perform:". $thistime. "Seconds. ". Time ();
?>
The last two times subtract, and then use the round () function to the time of execution to retain their own required decimal bit is OK. For example, this is the time required to compute the loop 1 million times: 0.116 seconds, as shown in the following figure:
For the sake of the neatness of the program, we can write this code as a class, introduce it in, and then instantiate the class before the program starts, and then call a method to accomplish this function.