-
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;
- }
- 现在可以轻松地检查任何一段代码的执行时间了,甚至我们可以同时使用多个计时器,只需在使用上述的几个函数时设定不同的参数作为计时器的名称就可以了。
相关文章: