• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

快速找到你的页面生成速度

PHP 开心洋葱 2514次浏览 0个评论

快速找到你的页面生成速度

当你认为你有一个耗时的脚本,使用这些功能来找出生成页面需要多久时间。就叫第一个函数中的第一个脚本,最后最后一个函数,将报告运行多少时间。您可以使用这个尝试如果您可以优化您的脚本使它更快。

<?
    $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);
?>


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明快速找到你的页面生成速度
喜欢 (0)

您必须 登录 才能发表评论!

加载中……