久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

php測試程序運行速度和頁面執行速度的代碼

瀏覽:92日期:2022-06-06 13:05:01

microtime() 函數返回當前 Unix 時間戳的微秒數。用于檢測程序執行時間的函數,也是PHP內置的時間函數之一,在PHP中可以用于對程序執行時間的判斷,以及相同功能函數的執行效率高低快慢的判斷。

使用microtime() 函數測試程序運行速度和頁面執行速度的代碼如下:

 <?php
class timer {    
var $StartTime = 0;    
var $StopTime = 0;    
var $TimeSpent = 0;    
function start(){    
$this->StartTime = microtime();    
}    
 
function stop(){    
$this->StopTime = microtime();    
}    
 
function spent() {    
if ($this->TimeSpent) {    
return $this->TimeSpent;    
} else {    
$StartMicro = substr($this->StartTime,0,10);    
$StartSecond = substr($this->StartTime,11,10);    
$StopMicro = substr($this->StopTime,0,10);    
$StopSecond = substr($this->StopTime,11,10);    
$start = floatval($StartMicro) + $StartSecond;    
$stop = floatval($StopMicro) + $StopSecond;    
$this->TimeSpent = $stop - $start;    
return round($this->TimeSpent,8)."秒";    
}  
} // end function spent();    
 
} //end class timer;  
 
//$timer = new timer;//實例化測試類  
//$timer->start();//放在代碼開始執行的測試點

//$timer->stop();   //放在代碼執行結束的測試點
//print_r("</br>運行時間為: ".$timer->spent()) ;
//unset($timer); 

到此這篇關于php測試程序運行速度和頁面執行速度的代碼的文章就介紹到這了,更多相關php測試執行速度代碼內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: PHP
主站蜘蛛池模板: 水城县| 宜章县| 观塘区| 龙陵县| 寻甸| 定兴县| 石河子市| 甘南县| 明光市| 宝应县| 昭苏县| 神农架林区| 凉山| 江北区| 门源| 翼城县| 滁州市| 兴化市| 东辽县| 松滋市| 青田县| 连平县| 滦平县| 博客| 江北区| 安国市| 桃源县| 天全县| 布拖县| 威远县| 石城县| 铜梁县| 和林格尔县| 磐安县| 永川市| 华安县| 普陀区| 嘉黎县| 思茅市| 云安县| 囊谦县|