php測試程序運行速度和頁面執(zhí)行速度的代碼
更新時間:2022年12月13日 17:31:08 投稿:yin
microtime()函數返回當前 Unix 時間戳的微秒數。用于檢測程序執(zhí)行時間的函數,也是PHP內置的時間函數之一,在PHP中可以用于對程序執(zhí)行時間的判斷,以及相同功能函數的執(zhí)行效率高低快慢的判斷。
microtime() 函數返回當前 Unix 時間戳的微秒數。用于檢測程序執(zhí)行時間的函數,也是PHP內置的時間函數之一,在PHP中可以用于對程序執(zhí)行時間的判斷,以及相同功能函數的執(zhí)行效率高低快慢的判斷。
使用microtime() 函數測試程序運行速度和頁面執(zhí)行速度的代碼如下:
<?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();//放在代碼開始執(zhí)行的測試點
//$timer->stop(); //放在代碼執(zhí)行結束的測試點
//print_r('</br>運行時間為: '.$timer->spent()) ;
//unset($timer); 到此這篇關于php測試程序運行速度和頁面執(zhí)行速度的代碼的文章就介紹到這了,更多相關php測試執(zhí)行速度代碼內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Zend Framework教程之請求對象的封裝Zend_Controller_Request實例詳解
這篇文章主要介紹了Zend Framework教程之請求對象的封裝Zend_Controller_Request用法,結合實例形式詳細分析了請求對象封裝的原理,使用方法與相關注意事項,需要的朋友可以參考下2016-03-03
Zend Framework教程之路由功能Zend_Controller_Router詳解
這篇文章主要介紹了Zend Framework教程之路由功能Zend_Controller_Router,詳細分析了路由功能Zend_Controller_Router的原理,使用技巧與相關注意事項,需要的朋友可以參考下2016-03-03

