class runtime { var $StartTime = 0; var $StopTime = 0; function get_microtime() { list($usec,$sec)=explode(' ',microtime());return((float)$usec+(float)$sec); } function start() { $this->StartTime=$this->get_microtime(); } function stop(){ $this->StopTime=$this->get_microtime(); } function spent() { return round(($this->StopTime-$this->StartTime),6); } }
先在php中加入这个类。然后在能够访问的位置新建这个类的对象
程序的开始位置写入
$runtime = new runtime (); $runtime->start (); //程序的结束位置写入 $this->view->treeType = $treeType; $runtime->stop (); echo 'Processed in ', $runtime->spent (), ' second(s).'; //就可以实现对于一段程序运行时间的就算了