您的位置:首页 > 编程语言 > PHP开发

php 计算脚本执行时间

2015-02-27 14:27 399 查看
//修改php的默认时区
date_default_timezone_get('PRC');

//使用微妙计算php脚本执行时间

echo microtime(); echo " 返回当前unix时间戳和微秒数";
echo "<br>";

class Timer{
private $startTime;
private $stopTime;

function __construct(){
$this->startTime=0;
$this->stopTime=0;
}

function start(){
$this->startTime=microtime(true);
}

function stop(){
$this->stopTime=microtime(true);

}

function spent(){
return round(($this->stopTime - $this->startTime),4);
}

}

$timer= new Timer();
$timer->start();
usleep(1000);
$timer->stop();

echo "执行该脚本用时<b>".$timer->spent()."</b>秒<br>";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php