获得页面执行时间

<?php
header("Content-type:text/html;charset=utf-8");
class runtime
{
    private $begintime = 0;
    private $endtime   = 0;
    private function gettime()
    {
        list($usec,$sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
    }
    public function begin()
    {
        $this->begintime = $this->gettime();
    }
    public function end()
    {    
        $this->endtime = $this->gettime();
    }
    public function spent()
    {
        return round(($this->endtime - $this->begintime) * 1000, 1);
    }
}
$runtime = new runtime();
$runtime->begin();
for ($i=0; $i < 10055; $i++) { 
    echo $i;
}
$runtime->end();
echo '页面执行时间'.$runtime->spent().'毫秒';
?> 

 

posted on 2019-06-17 17:05  夏沫忆香  阅读(373)  评论(0编辑  收藏  举报