php 计算脚本执行时间

来源:互联网 发布:苹果应用无法连接网络 编辑:程序博客网 时间:2024/05/22 03:18
//修改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>";
0 0
原创粉丝点击