看板 PHP 關於我們 聯絡資訊
※ 引述《tkdmaf (皮皮快跑)》之銘言: : ※ 引述《chan15 (ChaN)》之銘言: : : 請教一下,有沒有哪邊有不錯的測試程式碼執行時間軟體 : : 一個頁面「多段」測試,顯示多段結果的 ^^^^ 請用 pear 的 benchmark pkg http://pear.php.net/package/Benchmark/ require('/usr/share/php/Benchmark/Timer.php'); $timer = new Benchmark_Timer(); $timer->start(); $timer->setMarker('MethodStart'); /* 寫想測試的方法 */ $timer->setMarker('MethodStop'); $timer->setMarker('FunctionStart'); /* 寫想測試時間的函式 */ $timer->setMarker('FunctionStop'); $timer->timeElapsed('MethodStart', 'MethodStop'); $timer->timeElapsed('FunctionStart', 'FunctionStop'); /* 以此類推,可以自己多設一些 Marker 下去測試 */ $timer->stop(); $timer->display(); 這樣會有你要的測試結果。 另外如果要細一點的執行效能, 也可以考慮安裝 xdebug 或是 xhprof (pecl 內都有)。 : 自己隨手寫一個: : <?php : class effect_time { : var $start_time; : var $end_time; : function start(){ : $this->start_time = $this->_return_time(); : return $this->start_time.'<br>'; : } : function end(){ : $this->end_time = $this->_return_time(); : return $this->end_time.'<br>'; : } : function result(){ : echo $this->end_time - $this->start_time; : } : function _return_time(){ : list($sec,$min) = explode(' ',microtime()); : return $min+$sec; : } : } : ?> : 載入之後: : $effect_time = new $effect_time; : 在要測試的程式起始處: : $effect_time->start(); : 終止處: : $effect_time->end(); : 若要看起始或終始時間前面直接加echo。 : 若要在最後看,就把$effect_time->start_time或是end_time直接印出來。 : 效能時間:$effect_time->result(); : 大致上是這樣。 建議使用 pear 的套件,功能比較全面。 -- The Internet: where men are men, women are men, and children are FBI agents. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.89.121.16 ※ 編輯: roga 來自: 202.89.121.16 (07/29 14:08)