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.