获得页面执行时间

浏览:5205 发布日期:2013/10/17 分类:基础算法
获得页面执行时间
<?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().'毫秒';
?> 
评论( 相关
后面还有条评论,点击查看>>