Today, in order to test the running time of the program, I specially wrote such a class and added comments. I hope this class is very simple for everyone, it mainly uses the list () function of several function arrays, and splits the string into an array function explode () to obtain the timestamp and microseconds. the code is as follows:
The code is as follows:
Class runTime {
Private $ starTime; // start time
Private $ stopTime; // end time
Private function getMicTime (){
$ Mictime = microtime (); // Obtain the timestamp and number of microseconds
List ($ usec, $ sec) = explode ("", $ mictime); // splits the number of microseconds into an array and converts it to a variable for processing.
Return (float) $ usec + (float) $ sec; // forces the converted data to be processed by float points.
}
Public function star () {// Obtain the start time
$ This-> starTime = $ this-> getMicTime ();
}
Public function stop () {// Obtain the end time
$ This-> stopTime = $ this-> getMicTime ();
}
Public function spent () {// computing program duration
Return round ($ this-> stopTime-$ this-> starTime) * 1000; // get the number of milliseconds
}
}
// Example
$ Time = new runTime ();
$ Time-> star ();
For ($ I = 1; $ I <= 1000; $ I ++ ){
Echo ("");
}
$ Time-> stop ();
Echo $ time-> spent ();
?>