Php code used to calculate the program running time
Source: Internet
Author: User
A php class used to learn how long your program runs. For more information, see
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 ();
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.