php查看运行时间、内存消耗

来源:互联网 发布:淘宝店铺的优势怎么写 编辑:程序博客网 时间:2024/05/29 04:38
<?php/*计算运行时间*/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) * 1000, 1);     }     /*格式化当前内存消耗*/    function memory(){        $size = memory_get_usage();        $unit = array('b','kb','mb','gb','tb','pb');         return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];     } }?>