計算 PHP 指令碼執行時間的 PHP 程式


要計算 PHP 指令碼的執行時間,程式碼如下 −

示例

 即時演示

<?php
$start = microtime(true);
$val=1;
for($i = 1; $i <=1500; $i++)
{
   $val++;
}
$end = microtime(true);
$exec_time = ($end - $start);
echo "The execution time of the PHP script is : ".$exec_time." sec";
?>

輸出

The execution time of the PHP script is : 1.69 sec

‘Microtime’ 函式可用於檢查 PHP 指令碼執行完成所花費的時間。當代碼開始執行時,記錄時間,程式碼完成後,生成另一個時間戳,結束時間和開始時間之間的差值就是指令碼完成其執行所花費的時間。

更新於: 02-Jul-2020

622 個瀏覽量

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.