«
一个测试页面执行时间的类

时间:2008-5-31    作者:Deri    分类: 分享


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