当前位置:首页 > 计算页面执行时间

计算页面执行时间

点击次数:1510  更新日期:2011-01-02
\n

以下类定义了一个计时器,将你的执行脚本加入到”容器”内即可(请看注释)


\n<?
\nclass timer
\n{ var StartTime = 0;
\nvar StopTime = 0;
\nvar TimeSpent = 0;

\n

function start(){
\nthis->StartTime = microtime();}
\n function stop(){
\n this->StopTime = microtime();}
\n function spent(){
\n if (this->TimeSpent) {
\n return this->TimeSpent;
\n } else {
\nStartMicro = substr(this->StartTime,0,10);
\nStartSecond = substr(this->StartTime,11,10);
\nStopMicro  = substr(this->StopTime,0,10);
\nStopSecond = substr(this->StopTime,11,10);
\nstart = doubleval(StartMicro) + StartSecond;
\nstop = doubleval(StopMicro) + StopSecond;
\nthis->TimeSpent = stop – start;
\nreturn substr(this->TimeSpent,0,8).”秒”;
\n }
\n }// end function spent();
\n}//end class timer;
\n//例子
\n timer = new timer;
\n timer->start();
\n/*
\n你的代码放在此处
\n*/

\n

timer->stop();
\necho “执行本SCRIPT共”.timer->spent();
\n?>

\n