Php page execution time program code

Source: Internet
Author: User
Page execution time calculation is just a rough process. We put the initialization function of the program computing program at the top of the page, and then put the calculation function at the bottom of the page, then, when the page is executed, the related values can be calculated. the following shows the instance code nbsp...

Page execution time calculation is just a rough process. We put the initialization function of the program computing program at the top of the page, and then put the calculation function at the bottom of the page, after the page is executed, the related values can be calculated. See the example below.

Code

The code is as follows:

Class runtime
{
Var $ StartTime = 0;
Var $ StopTime = 0;

Function get_microtime ()
{
List ($ usec, $ sec) = explode ('', microtime ());
Return (float) $ usec + (float) $ sec );
}

Function start ()
{
$ This-> StartTime = $ this-> get_microtime ();
}

Function stop ()
{
$ This-> StopTime = $ this-> get_microtime ();
}

Function spent ()
{
Return round ($ this-> StopTime-$ this-> StartTime) * 1000, 1 );
}

}


// Example
$ Runtime = new runtime;
$ Runtime-> start ();

// Start your code

$ A = 0;
For ($ I = 0; I I <1000000; $ I ++)
{
$ A + = $ I;
}

// Your code ends

$ Runtime-> stop ();
Echo "page Execution time:". $ runtime-> spent (). "millisecond ";
?>


I will not talk about the calling method. we just need to pay attention that $ runtime-> start (); and $ runtime-> spent () are required, otherwise, it is invalid and cannot be placed on the cache page or in the html page.



Permanent link:

Reprint at will! Include the article address.

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.