Skip to content

Instantly share code, notes, and snippets.

@hnw
Created Jul 17, 2017
Embed
What would you like to do?
<?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