Skip to content

Instantly share code, notes, and snippets.

@hnw
Created July 17, 2017 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnw/91c5faa5ec35584166ac457342952caa to your computer and use it in GitHub Desktop.
Save hnw/91c5faa5ec35584166ac457342952caa to your computer and use it in GitHub Desktop.
<?php
$sleep_time = 0;
$loop = 1000;
if (preg_match('/^(\d+)s$/', $argv[1])) {
$sleep_time = (int)$argv[1];
}
$usleep_time = (isset($argv[1]) && $argv[1] > 0) ? (int)$argv[1] : 1000;
if ($sleep_time > 0) {
printf("sleep%d\n", $sleep_time);
for ($i = 0; $i < $loop; $i++) {
$ts1 = gettimeofday();
sleep($sleep_time);
$ts2 = gettimeofday();
$delta = ($ts2['sec']-$ts1['sec'])*1000000+($ts2['usec']-$ts1['usec']);
echo $delta, "\n";
}
} else {
printf("usleep%d\n", $usleep_time);
for ($i = 0; $i < $loop; $i++) {
$ts1 = gettimeofday();
usleep($usleep_time);
$ts2 = gettimeofday();
$delta = ($ts2['sec']-$ts1['sec'])*1000000+($ts2['usec']-$ts1['usec']);
echo $delta, "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment