欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php統(tǒng)計(jì)時(shí)間和內(nèi)存使用情況示例分享

 更新時(shí)間:2014年03月13日 10:16:38   作者:  
這篇文章主要介紹了php統(tǒng)計(jì)時(shí)間和內(nèi)存使用情況示例,大家直接調(diào)用下面的方法就可以使用,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

/**
 * 記錄和統(tǒng)計(jì)時(shí)間(微秒)和內(nèi)存使用情況
 * 使用方法:
 * <code>
 * G('begin'); // 記錄開始標(biāo)記位
 * // ... 區(qū)間運(yùn)行代碼
 * G('end'); // 記錄結(jié)束標(biāo)簽位
 * echo G('begin','end',6); // 統(tǒng)計(jì)區(qū)間運(yùn)行時(shí)間 精確到小數(shù)后6位
 * echo G('begin','end','m'); // 統(tǒng)計(jì)區(qū)間內(nèi)存使用情況
 * 如果end標(biāo)記位沒有定義,則會(huì)自動(dòng)以當(dāng)前作為標(biāo)記位
 * 其中統(tǒng)計(jì)內(nèi)存使用需要 MEMORY_LIMIT_ON 常量為true才有效
 * </code>
 * @param string $start 開始標(biāo)簽
 * @param string $end 結(jié)束標(biāo)簽
 * @param integer|string $dec 小數(shù)位或者m
 * @return mixed
 */
function G($start,$end='',$dec=4) {
    static $_info       =   array();
    static $_mem        =   array();
    if(is_float($end)) { // 記錄時(shí)間
        $_info[$start]  =   $end;
    }elseif(!empty($end)){ // 統(tǒng)計(jì)時(shí)間和內(nèi)存使用
        if(!isset($_info[$end])) $_info[$end]       =  microtime(TRUE);
        if(MEMORY_LIMIT_ON && $dec=='m'){
            if(!isset($_mem[$end])) $_mem[$end]     =  memory_get_usage();
            return number_format(($_mem[$end]-$_mem[$start])/1024);         
        }else{
            return number_format(($_info[$end]-$_info[$start]),$dec);
        }      

    }else{ // 記錄時(shí)間和內(nèi)存使用
        $_info[$start]  =  microtime(TRUE);
        if(MEMORY_LIMIT_ON) $_mem[$start]           =  memory_get_usage();
    }
}

相關(guān)文章

最新評(píng)論