国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語言 > PHP > 正文

一個(gè)php計(jì)算程序運(yùn)行時(shí)間的類

2024-09-04 11:45:33
字體:
供稿:網(wǎng)友

一個(gè)可以統(tǒng)計(jì)你程序的運(yùn)行時(shí)間長(zhǎng)知的php類,實(shí)例代碼如下:

  1. class Timer {   
  2.     private $StartTime = 0;//程序運(yùn)行開始時(shí)間 
  3.     private $StopTime  = 0;//程序運(yùn)行結(jié)束時(shí)間 
  4.     private $TimeSpent = 0;//程序運(yùn)行花費(fèi)時(shí)間 
  5.     function start(){//程序運(yùn)行開始 
  6.         $this->StartTime = microtime();   
  7.     }   
  8.     function stop(){//程序運(yùn)行結(jié)束 
  9.         $this->StopTime = microtime();   
  10.     }   
  11.     function spent(){//程序運(yùn)行花費(fèi)的時(shí)間 
  12.         if ($this->TimeSpent) {   
  13.             return $this->TimeSpent;   
  14.         } else { 
  15.          list($StartMicro$StartSecond) = explode(" "$this->StartTime); 
  16.          list($StopMicro$StopSecond) = explode(" "$this->StopTime); 
  17.             $start = doubleval($StartMicro) + $StartSecond
  18.             $stop = doubleval($StopMicro) + $StopSecond
  19.             $this->TimeSpent = $stop - $start
  20.             return substr($this->TimeSpent,0,8)."秒";//返回獲取到的程序運(yùn)行時(shí)間差 
  21.         }   
  22.     }   
  23. }   
  24. $timer = new Timer();   
  25. $timer->start(); 
  26. //...程序運(yùn)行的代碼 
  27. $timer->stop(); 
  28. echo "程序運(yùn)行時(shí)間為:".$timer->spent(); 

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 綦江县| 读书| 兴仁县| 梅河口市| 夏河县| 汤阴县| 广安市| 横山县| 永靖县| 丰镇市| 台北市| 横峰县| 澎湖县| 南昌市| 蓝山县| 新沂市| 桂阳县| 始兴县| 修文县| 崇信县| 灵寿县| 武山县| 江都市| 玉溪市| 黄浦区| 乌海市| 墨脱县| 无极县| 沙洋县| 类乌齐县| 长泰县| 科技| 个旧市| 正安县| 青海省| 津市市| 香港 | 洪洞县| 阳江市| 桓仁| 丰都县|