Php code used to calculate the program running time. Copy the code as follows: classt#{ private $ StartTime0; start time of the program running private $ StopTime0; end time of the program running private $ TimeSpent0; run cost
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 http://www.bkjia.com/PHPjc/326150.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326150.htmlTechArticle code is as follows: class Timer {private $ StartTime = 0; // program running start time private $ StopTime = 0; // program running end time private $ TimeSpent = 0; // program running cost...