- 論壇徽章:
- 0
|
經(jīng)?吹胶芏嗑W(wǎng)站的頁面底部有個"頁面執(zhí)行時間"的冬冬,如果你是程序員的話,還能夠用它調(diào)試自己的程序執(zhí)行效率,其實原理很簡單,相信你看過本文后,很容易就能實現(xiàn).
PHP: // 說明:PHP 計算頁面執(zhí)行時間 // 整理:http://www.CodeBit.cn class timer { 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() { return round(($this->StopTime - $this->StartTime) * 1000, 1); } } /* //例子 $timer = new timer; $timer->start(); //你的代碼開始 $a = 0; for($i=0; $i{ $a += $i; } //你的代碼結(jié)束 $timer->stop(); echo "頁面執(zhí)行時間: ".$timer->spent()." 毫秒"; */ ?>
本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/1222/showart_1914434.html |
|