// 實例1 /** * @start time */ function proStartTime() { global $startTime; $mtime1 = explode(" ", microtime()); $startTime = $mtime1[1] + $mtime1[0]; } /** * @End time */ function proEndTime() { global $startTime,$set; $mtime2 = explode(" ", microtime()); $endtime = $mtime2[1] + $mtime2[0]; $totaltime = ($endtime - $startTime); $totaltime = number_format($totaltime, 7); echo "<br/>process time: ".$totaltime; } // 程序調用開始記時 proStartTime(); sleep(1); // sleep() 延時代碼執行若干秒 proEndTime(); // 程序在每一段所消耗的執行時間 sleep(2); proEndTime(); sleep(3); proEndTime(); // 實例2 $t1 = microtime(true); sleep(3); $t2 = microtime(true); echo '程序耗時'.round($t2-$t1,3).'秒'; ?>