入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

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

创建时间:2013-04-11 投稿人: 浏览次数:163
<?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]; 
    } 
}
?>

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像