分享

php页面执行时间

 竹林书屋@ 2012-03-03
<?php
02class runtime
03{
04    var $StartTime = 0;
05    var $StopTime = 0;
06  
07    function get_microtime()
08    {
09        list($usec$sec) = explode(' ', microtime());
10        return ((float)$usec + (float)$sec);
11    }
12  
13    function start()
14    {
15        $this->StartTime = $this->get_microtime();
16    }
17  
18    function stop()
19    {
20        $this->StopTime = $this->get_microtime();
21    }
22  
23    function spent()
24    {
25        return round(($this->StopTime - $this->StartTime) * 1000, 1);
26    }
27  
28}
29  
30  
31//例子
32$runtimenew runtime;
33$runtime->start();
34  
35//你的代码开始
36  
37$a = 0;
38for($i=0; $i<1000000; $i++)
39{
40    $a += $i;
41}
42  
43//你的代码结束
44  
45$runtime->stop();
46echo "页面执行时间: ".$runtime->spent()." 毫秒";
47?>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多