PHP test program running time class

Source: Internet
Author: User
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 ();
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.