PHP计算程序执行时间类

来源:互联网 发布:linux定时任务不执行 编辑:程序博客网 时间:2024/06/05 07:23
//引用类文件,并执行start()函数,做完工作后执行stop()函数,输出页面执行时间spent()include("runtime.php");$runtime= new runtime;$runtime->start();             // do something $runtime->stop(); echo "<span>页面执行时间:".$runtime->spent()."秒</span>";


下面是runtime.php 类文件

<?phpclass 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) , 1);     }  }?>


0 0