<?php
$loop = 100000000;
$sum = 0;
// 開始時間を取得
$time_start = microtime(true);
for ($i = 1; $i <= $loop; $i++) {
$sum = $sum + $i;
}
print '1から' . $loop . 'まで足した合計値は' . $sum ."\n";
// 終了時間を取得
$time_end = microtime(true);
$time = $time_end - $time_start;
echo '実行に要した時間は' . round($time,3 ). '秒です。';
実装結果
<?php
$loop = 150000000;
$sum = 0;
$start = hrtime(true); // 計測開始時間
// 計測したい処理
for ($i = 1; $i <= $loop; $i++) {
$sum = $sum + $i;
}
$end = hrtime(true); // 計測終了時間
// 終了時間から開始時間を引くと処理時間になる
echo '処理時間:'.($end - $start).'ナノ秒';
?>