最新消息:

PHP函数第26款:获取代码间的执行时间ExecTime

PHP扩展函数 杨红伟 5714浏览 0评论

一:函数简介

有时候,我们需要计算下两段代码间的执行时间,以达到程序的最佳执行效率。这款函数就帮到了我们!

演示地址: http://www.ijquery.cn/phpfunction/ExecTime/demo1.php

下载地址: http://www.ijquery.cn/phpfunction/ExecTime/ExecTime.zip

二:函数应用

$t1 = ExecTime();  在一段内容处理之后:   $t2 = ExecTime();   我们可以将2个时间的差值输出:echo $t2-$t1;

三:函数代码

/**
 *  获取执行时间
 *  例如:$t1 = ExecTime();
 *       在一段内容处理之后:
 *       $t2 = ExecTime();
 *  我们可以将2个时间的差值输出:echo $t2-$t1;
 *
 *  @return    int
 */
if ( ! function_exists('ExecTime'))
{
    function ExecTime()
    {
        $time = explode(" ", microtime());
        $usec = (double)$time[0];
        $sec = (double)$time[1];
        return $sec + $usec;
    }
}


Warning: Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /www/wwwroot/www.ijquery.cn/wp-content/themes/d8-3.0/comments.php on line 17
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址