Copy code The code is as follows:
class Timer {
private $StartTime = 0;//Program running start time
private $StopTime = 0;//The end time of program running
private $TimeSpent = 0;//The time it takes to run the program
function start(){//The start of program running
$this->StartTime = microtime();
}
function stop(){//The program ends
$this->StopTime = microtime();
}
function spent(){//Program Time spent running
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 ";//Return the obtained program running time difference
}
}
}
$timer = new Timer();
$timer->start();
/ /...The program running code
$timer->stop();
echo "The program running time is:".$timer->spent();
http://www.bkjia.com/PHPjc/326150.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326150.htmlTechArticleCopy the code as follows: class Timer { private $StartTime = 0;//Program running start time private $StopTime = 0;//Program running end time private $TimeSpent = 0;//Program running cost...