Created
June 7, 2017 11:09
-
-
Save kkkw/fe80f314b07582e3cb4503bd28e961b2 to your computer and use it in GitHub Desktop.
負荷対策
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$bench_start = microtime(true); | |
$process_at_least = 0.05; | |
foreach (range(1,3000) as $i){ | |
$process_start = microtime(true); | |
usleep(0.05 * 1000000); | |
$process_end = microtime(true); | |
$process_time = $process_end - $process_start; | |
echo 'proc:', $process_time,PHP_EOL; | |
if($process_at_least < $process_time){ | |
continue; | |
} | |
$sleep_time = $process_at_least - $process_time; | |
echo 'sleep:', $sleep_time,PHP_EOL; | |
usleep($sleep_time * 1000000); | |
echo 'index:', $i, PHP_EOL; | |
} | |
$bench_end = microtime(true); | |
$bench_time = $bench_end - $bench_start; | |
echo 'bench:', "$bench_time seconds\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment