復制代碼 代碼如下:
<?php
class runTime {
private $starTime;//開始時間
private $stopTime;//結束時間
private function getMicTime(){
$mictime=microtime();//獲取時間戳和微秒數(shù)
list($usec,$sec)=explode(" ",$mictime);//把微秒數(shù)分割成數(shù)組并轉換成變量處理
return (float)$usec+(float)$sec;//把轉換后的數(shù)據強制用浮點點來處理
}
public function star(){//獲取開始時間
$this->starTime=$this->getMicTime();
}
public function stop(){//獲取結束時間
$this->stopTime=$this->getMicTime();
}
public function spent(){//計算程序持續(xù)時間
return round($this->stopTime-$this->starTime)*1000;//獲取毫秒數(shù)
}
}
//舉例
$time=new runTime();
$time->star();
for ($i=1;$i<=1000;$i++){
echo("a");
}
$time->stop();
echo $time->spent();
?>
新聞熱點
疑難解答