Copy code code as follows:
class Timer {
Private $StartTime = 0;//program run start time
Private $StopTime = 0;//program run end time
Private $TimeSpent = 0;//program Elapsed time
Function start () {//program run start
$this->starttime = microti Me ();
}
Function Stop () {//program run over
$this->stoptime = Microtime ();
}
Function spent () {//The time spent 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,0,8). Seconds ";//returns the run time of the obtained program
}
}
}
$timer = new timer ();
$timer->start ();
//... Program running Code
$timer->stop ();
echo "Program Elapsed Time:". $timer->spent ();