A php class that can measure the running time of your program. For more information, see. A php class that can measure the running time of your program. For more information, see.
Script ec (2); script
The Code is as follows: |
|
Class Timer { Private $ StartTime = 0; // the start time of the program. Private $ StopTime = 0; // end time of the program running Private $ TimeSpent = 0; // time spent on running the program Function start () {// start the program $ This-> StartTime = microtime (); } Function stop () {// The End of the program running $ This-> StopTime = microtime (); } Function spent () {// time spent on running the program If ($ this-> TimeSpent ){ Return $ this-> TimeSpent; } Else { List ($ StartMicro, $ StartSecond) = explode ("", $ this-> StartTime ); List ($ StopMicro, $ StopSecond) = explode ("", $ this-> StopTime ); $ Start = doubleval ($ StartMicro) + $ StartSecond; $ Stop = doubleval ($ StopMicro) + $ StopSecond; $ This-> TimeSpent = $ stop-$ start; Return substr ($ this-> TimeSpent,). "seconds"; // return the time difference between the obtained programs. } } } $ Timer = new Timer (); $ Timer-> start (); // Code for running the program... $ Timer-> stop (); Echo "program running time:". $ timer-> spent ();
|