计算php页面执行时间

[代码] [PHP]代码

01 <?php
02 class 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;
38 for($i=0; $i<1000000; $i++)
39 {
40     $a += $i;
41 }
42   
43 //你的代码结束
44   
45 $runtime->stop();
46 echo "页面执行时间: ".$runtime->spent()." 毫秒";
47 ?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值