PHP 计算页面执行时间

<p>PHP 计算页面执行时间</p> <p>&lt; ?php<br /> class runtime<br /> {<br /> var $StartTime = 0;<br /> var $StopTime = 0;<br /> <br /> function get_microtime()<br /> {<br /> list($usec, $sec) = explode(&#39; &#39;, microtime());<br /> return ((float)$usec + (float)$sec);<br /> }<br /> <br /> function start()<br /> {<br /> $this-&gt;StartTime = $this-&gt;get_microtime();<br /> }<br /> <br /> function stop()<br /> {<br /> $this-&gt;StopTime = $this-&gt;get_microtime();<br /> }<br /> <br /> function spent()<br /> {<br /> return round(($this-&gt;StopTime - $this-&gt;StartTime) * 1000, 1);<br /> }<br /> <br /> }<br /> <br /> <br /> //例子<br /> $runtime= new runtime;<br /> $runtime-&gt;start();<br /> <br /> //你的代码开始<br /> <br /> $a = 0;<br /> for($i=0; $i&lt;1000000; $i++)<br /> {<br /> $a += $i;<br /> }<br /> <br /> //你的代码结束<br /> <br /> $runtime-&gt;stop();<br /> echo &quot;页面执行时间: &quot;.$runtime-&gt;spent().&quot; 毫秒&quot;;<br /> <br /> ?&gt;</p>
RangeTime:0.010851s
RangeMem:204.82 KB
返回顶部 留言