php 计算执行时间的类用法示例
内容摘要
这篇文章主要为大家详细介绍了php 计算执行时间的类用法示例,具有一定的参考价值,可以用来参考一下。
有了这个php类,计算函数或者一段代码的执行时间就简单了,php用于计算执行
有了这个php类,计算函数或者一段代码的执行时间就简单了,php用于计算执行
文章正文
这篇文章主要为大家详细介绍了php 计算执行时间的类用法示例,具有一定的参考价值,可以用来参考一下。
有了这个php类,计算函数或者一段代码的执行时间就简单了,php用于计算执行时间的类本文实例讲述了php用于计算执行时间的类 ,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码如下:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <code class = "php" > /** * 计算函数或者一段代码的执行时间 * * @param * @arrange (www.idcnote.com) **/ class c_Timer { var $t_start = 0; var $t_stop = 0; var $t_elapsed = 0; function start() { $this ->t_start = microtime(); } function stop() { $this ->t_stop = microtime(); } function elapsed() { if ( $this ->t_elapsed) { return $this ->t_elapsed; } else { $start_u = substr ( $this ->t_start,0,10); $start_s = substr ( $this ->t_start,11,10); $stop_u = substr ( $this ->t_stop,0,10); $stop_s = substr ( $this ->t_stop,11,10); $start_total = doubleval( $start_u ) + $start_s ; $stop_total = doubleval( $stop_u ) + $stop_s ; $this ->t_elapsed = $stop_total - $start_total ; return $this ->t_elapsed; } } }; /* Here's an example usage: $timer = new c_Timer; $timer->start(); echo "<hr>"; $timer->stop(); echo $timer->elapsed(); */ </code> |
注:关于php 计算执行时间的类用法示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释