欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP測試程序運行時間的類

 更新時間:2012年02月05日 21:54:52   作者:  
今天,為了測試一斷程序的運行時間,特意寫了這么一個類,并添加了注釋,希望對大家有所幫助
類很簡單,主要是運用了幾個函數(shù)數(shù)組列表函數(shù)list(),字符串分割成數(shù)組函數(shù)explode(),獲取時間戳和微秒數(shù)microtime(),代碼如下:
復(fù)制代碼 代碼如下:

<?php
class runTime {
private $starTime;//開始時間
private $stopTime;//結(jié)束時間
private function getMicTime(){
$mictime=microtime();//獲取時間戳和微秒數(shù)
list($usec,$sec)=explode(" ",$mictime);//把微秒數(shù)分割成數(shù)組并轉(zhuǎn)換成變量處理
return (float)$usec+(float)$sec;//把轉(zhuǎn)換后的數(shù)據(jù)強制用浮點點來處理
}
public function star(){//獲取開始時間
$this->starTime=$this->getMicTime();
}
public function stop(){//獲取結(jié)束時間
$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();
?>

相關(guān)文章

最新評論