一个可以统计你程序的运行时间长知的php类,实例代码如下:
- class Timer {
- private $StartTime = 0;
- private $StopTime = 0;
- private $TimeSpent = 0;
- function start(){
- $this->StartTime = microtime();
- }
- function stop(){
- $this->StopTime = microtime();
- }
- function spent(){
- 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)."秒";
- }
- }
- }
- $timer = new Timer();
- $timer->start();
-
- $timer->stop();
- echo "程序运行时间为:".$timer->spent();
|