PHP test program running time class

Source: Internet
Author: User
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

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.