0
0

More than 3 years have passed since last update.

【php】処理速度を調査する

Last updated at Posted at 2021-05-21
<?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 ). '秒です。';

実装結果

image.png

<?php

$loop = 150000000;
$sum  = 0;

$start = hrtime(true); // 計測開始時間

// 計測したい処理

for ($i = 1; $i <= $loop; $i++) {
   $sum = $sum + $i;
}


$end = hrtime(true); // 計測終了時間

// 終了時間から開始時間を引くと処理時間になる
echo '処理時間:'.($end - $start).'ナノ秒';

?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0