Chinaunix首页 | 论坛 | 博客
  • 博客访问: 171322
  • 博文数量: 49
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 337
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-23 15:51
文章分类

全部博文(49)

文章存档

2014年(23)

2013年(26)

我的朋友

分类: PHP

2013-05-08 20:01:58

定义了一个用来记录页面执行时间的类runtime,在需要展示页面执行时间的php代码中,只需要引入该类并用$runtime= new runtime;的方式进行实例化,然后分别在页面开始位置调用该类下的start()方法开始记录时间,在页面结束位置调用stop()方法结束记录,最后调用spent()方法输出,输出的时间为毫秒。

本文参考自如下的内容: 。

代码如下:
/**
 * 页面执行时间
 * Edit
*/
$runtime= new runtime;//实例化类
$runtime->start();//执行开始记录方法
$runtime->stop();//结束记录并输出
echo "
执行时间为: ".$runtime->spent()."毫秒
";
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);
    }
}
?>
本文原始链接:
阅读(894) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~