A php test program running time class WEB development note www.chhua.com exercises every day to write a PHP test program running time class today, in order to test the program running time, specifically write such a class, and added comments to help you. Class is very simple, mainly... SyntaxHighlighter. all ();
A php test program running time class
WEB development notes www.chhua.com exercise every day to write a class of PHP test program running time
Today, in order to test the running time of the program, I wrote such a class and added comments, hoping to help you.
The class is very simple, mainly using several function array functions list (), string split into array functions explode (), get the timestamp and microsecond number of microtime (), 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 ();
?>
From WEB development notes W