快速找到你的页面生成速度
当你认为你有一个耗时的脚本,使用这些功能来找出生成页面需要多久时间。就叫第一个函数中的第一个脚本,最后最后一个函数,将报告运行多少时间。您可以使用这个尝试如果您可以优化您的脚本使它更快。
<? $timekeeper = array(); $timereport = array(); function start_track($item, $timekeeper) { $timeStart=gettimeofday(); $timeStart_uS=$timeStart["usec"]; $timeStart_S=$timeStart["sec"]; $item1 = $item . "_usec"; $item2 = $item . "_sec"; $timekeeper[$item1] = $timeStart_uS; $timekeeper[$item2] = $timeStart_S; return $timekeeper; } function end_track($item, $timekeeper, $timereport) { $timeEnd=gettimeofday(); $timeEnd_uS=$timeEnd["usec"]; $timeEnd_S=$timeEnd["sec"]; $item1 = $item . "_usec"; $item2 = $item . "_sec"; $start_uS = $timekeeper[$item1]; $start_S = $timekeeper[$item2]; $ExecTime_S = ($timeEnd_S+($timeEnd_uS/1000000))-($start_S+($start_uS/1000000)); $timereport[$item] = $ExecTime_S; return $timereport; } function time_report($timereport) { while(list($key, $time) = each($timereport)) { print "$key - $time sec.<br>\n"; } } // use these lines to perform the function calls. Make sure that you // use the name name for the start and stop functions or it won't work // make as many calls as you want wherever you want then use time_report // to list all the different times $timekeeper = start_track("stringofyourchoice", $timekeeper); $timereport = end_track("stringofyourchoice", $timekeeper, $timereport); // when all is said and done, call this after last end_track has been called time_report($timereport); ?>