码迷,mamicode.com
首页 > Web开发 > 详细

PHP 计算页面执行时间

时间:2014-11-12 17:47:40      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   sp   for   div   on   

PHP 计算页面执行时间

 1 < ?php
 2 class runtime
 3 { 
 4     var $StartTime = 0; 
 5     var $StopTime = 0; 
 6  
 7     function get_microtime() 
 8     { 
 9         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 $runtime= new runtime;
33 $runtime->start();
34  
35 //你的代码开始
36  
37 $a = 0;
38 for($i=0; $i&lt;1000000; $i++)
39 {
40     $a += $i;
41 }
42  
43 //你的代码结束
44  
45 $runtime->stop();
46 echo "页面执行时间: ".$runtime->spent()." 毫秒";
47  
48 ?>

 

PHP 计算页面执行时间

标签:style   blog   io   color   ar   sp   for   div   on   

原文地址:http://www.cnblogs.com/CHEUNGKAMING/p/4092872.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!