程序执行速度测试函数

通过配置name可以设置多个计时器

//开始时间
function ss_timing_start ($name = default) { 
  global $ss_timing_start_times; 
  $ss_timing_start_times[$name] = explode( , microtime()); 

//结束时间
function ss_timing_stop ($name = default) { 
  global $ss_timing_stop_times; 
  $ss_timing_stop_times[$name] = explode(, microtime()); 

//执行时间
function ss_timing_current ($name = default) { 
  global $ss_timing_start_times, $ss_timing_stop_times; 
  if (!isset($ss_timing_start_times[$name])) { 
    return 0; 
  } 
  if (!isset($ss_timing_stop_times[$name])) { 
    $stop_time = explode(, microtime()); 
  } 
  else { 
    $stop_time = $ss_timing_stop_times[$name]; 
  } 
  $current = $stop_time[1] - $ss_timing_start_times[$name][1]; 
  $current += $stop_time[0] - $ss_timing_start_times[$name][0]; 
  return $current; 
}  

猜你喜欢

转载自www.cnblogs.com/plxm/p/9724661.html