<p> <code><?<br />class timer { <br /> var $StartTime = 0; <br /> var $StopTime = 0; <br /> var $TimeSpent = 0; <br /> function start(){ <br /> $this->StartTime = microtime(); <br /> } <br /> function stop(){ <br /> $this->StopTime = microtime(); <br /> } <br /> function spent() { <br /> if ($this->TimeSpent) { <br /> return $this->TimeSpent; <br /> } else { <br /> $StartMicro = substr($this->StartTime,0,10); <br /> $StartSecond = substr($this->StartTime,11,10); <br /> $StopMicro = substr($this->StopTime,0,10); <br /> $StopSecond = substr($this->StopTime,11,10); <br /> $start = doubleval($StartMicro) + $StartSecond; <br /> $stop = doubleval($StopMicro) + $StopSecond; <br /> $this->TimeSpent = $stop - $start; <br /> return substr($this->TimeSpent,0,8)."秒"; <br /> } <br /> } // end function spent(); <br />} //end class timer; <br />//例子: <br /> $timer = new timer; <br /> $timer->start(); <br />/*<br />你的代码放在此处<br />*/<br /> $timer->stop(); <br /> echo "执行本SCRIPT共".$timer->spent(); <br />?></code></p>