新聞中心
這篇文章主要介紹“怎么用php實(shí)現(xiàn)計(jì)算程序運(yùn)行時(shí)間的類”,在日常操作中,相信很多人在怎么用php實(shí)現(xiàn)計(jì)算程序運(yùn)行時(shí)間的類問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”怎么用php實(shí)現(xiàn)計(jì)算程序運(yùn)行時(shí)間的類”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
復(fù)制代碼 代碼如下:
class Timer {
private $StartTime = 0;//程序運(yùn)行開始時(shí)間
private $StopTime = 0;//程序運(yùn)行結(jié)束時(shí)間
private $TimeSpent = 0;//程序運(yùn)行花費(fèi)時(shí)間
function start(){//程序運(yùn)行開始
$this->StartTime = microtime();
}
function stop(){//程序運(yùn)行結(jié)束
$this->StopTime = microtime();
}
function spent(){//程序運(yùn)行花費(fèi)的時(shí)間
if ($this->TimeSpent) {
return $this->TimeSpent;
} else {
list($StartMicro, $StartSecond) = explode(" ", $this->StartTime);
list($StopMicro, $StopSecond) = explode(" ", $this->StopTime);
$start = doubleval($StartMicro) + $StartSecond;
$stop = doubleval($StopMicro) + $StopSecond;
$this->TimeSpent = $stop - $start;
return substr($this->TimeSpent,0,8)."秒";//返回獲取到的程序運(yùn)行時(shí)間差
}
}
}
$timer = new Timer();
$timer->start();
//...程序運(yùn)行的代碼
$timer->stop();
echo "程序運(yùn)行時(shí)間為:".$timer->spent();
到此,關(guān)于“怎么用php實(shí)現(xiàn)計(jì)算程序運(yùn)行時(shí)間的類”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
網(wǎng)頁名稱:怎么用php實(shí)現(xiàn)計(jì)算程序運(yùn)行時(shí)間的類-創(chuàng)新互聯(lián)
分享鏈接:http://www.ef60e0e.cn/article/cdojoi.html