PHPスクリプトの実行時間を正確に測定する方法 質問する

PHPスクリプトの実行時間を正確に測定する方法 質問する

PHP の for ループの実行に何ミリ秒かかるかを知りたいです。

汎用アルゴリズムの構造はわかっていますが、PHP でそれを実装する方法がわかりません。

Begin
init1 = timer(); // where timer() is the amount of milliseconds from midnight
the loop begin
some code
the loop end
total = timer() - init1;
End

ベストアンサー1

あなたはmicrotimeこの機能。ドキュメント:

microtime— 現在のUnixタイムスタンプをマイクロ秒で返します


get_as_floatが に設定されている場合TRUEmicrotime()Unix エポックからの現在の時刻をマイクロ秒単位の精度で表した float を返します。

使用例:

$start = microtime(true);
while (...) {

}
$time_elapsed_secs = microtime(true) - $start;

おすすめ記事