计算php代码执行时间长短的类
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                计算php代码执行时间长短的类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            <?php 
/**
?* PHP腳本執行時間計算
?*/
class runtime
{
??? var $StartTime = 0;
??? var $StopTime = 0;
 
 
??? function get_microtime()
??? {
??????? list($usec, $sec) = explode(' ', microtime());
??????? return ((float)$usec + (float)$sec);
??? }
 
 
??? function start()
??? {
??????? $this->StartTime = $this->get_microtime();
??? }
 
 
??? function stop()
??? {
??????? $this->StopTime = $this->get_microtime();
??? }
 
 
??? function spent($echo=false,$title='')
??? {
??????? $spent = sprintf('%.4f',round(($this->StopTime - $this->StartTime) * 1000, 1)/1000);
??????? if($echo){
??????????? echo? $title."執行時間:{$spent}秒<br/>";
??????? }else{
??????????? return $spent;
??????? }
??? }
??? function clear()
??? {
??????? $this->StartTime = 0;
??????? $this->StopTime = 0;
??? }
 
 
}
 
 
#測試腳本代碼
$runtime= new runtime;
$runtime->start();
$a = 0;
for($i=0; $i<100000; $i++)
{
??? $a *= $i;
}
$runtime->stop();
 
 
$spent_time = $runtime->spent($echo=true, '測試腳本');
$runtime->clear();
 
?>
                        
                        
                        /**
?* PHP腳本執行時間計算
?*/
class runtime
{
??? var $StartTime = 0;
??? var $StopTime = 0;
??? function get_microtime()
??? {
??????? list($usec, $sec) = explode(' ', microtime());
??????? return ((float)$usec + (float)$sec);
??? }
??? function start()
??? {
??????? $this->StartTime = $this->get_microtime();
??? }
??? function stop()
??? {
??????? $this->StopTime = $this->get_microtime();
??? }
??? function spent($echo=false,$title='')
??? {
??????? $spent = sprintf('%.4f',round(($this->StopTime - $this->StartTime) * 1000, 1)/1000);
??????? if($echo){
??????????? echo? $title."執行時間:{$spent}秒<br/>";
??????? }else{
??????????? return $spent;
??????? }
??? }
??? function clear()
??? {
??????? $this->StartTime = 0;
??????? $this->StopTime = 0;
??? }
}
#測試腳本代碼
$runtime= new runtime;
$runtime->start();
$a = 0;
for($i=0; $i<100000; $i++)
{
??? $a *= $i;
}
$runtime->stop();
$spent_time = $runtime->spent($echo=true, '測試腳本');
$runtime->clear();
?>
總結
以上是生活随笔為你收集整理的计算php代码执行时间长短的类的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 交易基准日是什么意思(基准日是什么意思)
- 下一篇: 自制蔓越莓饼干的做法(蔓越莓饼干的做法烤
