PHP计算程序运行时间的类

时间:2023-03-09 16:23:57
PHP计算程序运行时间的类
<?php
class runTime{
private $starTime;
private $stopTime;
private function getMicTime(){
$mictime=microtime(true);
list($usec,$sec)=explode(' ',$mictime);
return (float)$usec+(float)$sec;
} public function star(){
$this->starTime=$this->getMicTime();
} public function stop(){
$this->stopTime=$this->getMicTime();
} public function spent(){
return round($this->stopTime-$this->starTime)*1000;//单位:毫秒数
}
} //类使用方法介绍
$time=new runTime();
$time->star();//该语句尽量写在代码段的最开始处 //程序代码段 $time->stop();//该语句最好写在代码段的最结尾处
echo $time->spent();

相关文章