Copy CodeThe code is as follows:
Class Timer {
Private $StartTime = 0;//program run start time
Private $StopTime = 0;//program Run end time
Private $TimeSpent = 0;//program takes time to run
function Start () {//program run start
$this->starttime = Microtime ();
}
function Stop () {//program run end
$this->stoptime = Microtime ();
}
function spent () {//time spent by program run
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 program run time difference that gets to
}
}
}
$timer = new timer ();
$timer->start ();
//... Code to run the program
$timer->stop ();
echo "Program run Time:". $timer->spent ();
http://www.bkjia.com/PHPjc/326150.html www.bkjia.com true http://www.bkjia.com/PHPjc/326150.html techarticle Copy the code as follows: Class Timer {Private $StartTime = 0;//program run start time Private $StopTime = 0;//program run end time Private $TimeSpent = 0;//path Cost of the order run ...