PHP 速度测试函数

  1. function ss_timing_start ($name = default) { 
  2.  global $ss_timing_start_times
  3.  $ss_timing_start_times[$name] = explode( , microtime()); 
  4. function ss_timing_stop ($name = default) { 
  5.  global $ss_timing_stop_times
  6.  $ss_timing_stop_times[$name] = explode(, microtime()); 
  7. function ss_timing_current ($name = default) { 
  8.  global $ss_timing_start_times$ss_timing_stop_times
  9.  if (!isset($ss_timing_start_times[$name])) { 
  10. return 0; 
  11.  } 
  12.  if (!isset($ss_timing_stop_times[$name])) { 
  13. $stop_time = explode(, microtime()); 
  14.  } 
  15.  else { 
  16. $stop_time = $ss_timing_stop_times[$name]; 
  17.  } 
  18.  $current = $stop_time[1] - $ss_timing_start_times[$name][1]; 
  19.  $current += $stop_time[0] - $ss_timing_start_times[$name][0]; 
  20.  return $current
  21. 现在可以轻松地检查任何一段代码的执行时间了,甚至我们可以同时使用多个计时器,只需在使用上述的几个函数时设定不同的参数作为计时器的名称就可以了。

 

posted on 2011-05-09 23:02  cn三少<script></script>  阅读(234)  评论(0编辑  收藏  举报

导航