PHP 速度测试函数

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

 

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

导航