[php-src] Issue #9084: usleep has 50µs+ overhead
| From: | terwey | Date: | Thu, 21 Jul 2022 12:36:32 +0000 |
| Subject: | [php-src] Issue #9084: usleep has 50µs+ overhead | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241969@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9084
Author: terwey
### Description
During some benchmarking I noticed that
usleep() adds roughly 54µs overhead to each
call even when the time is set to 0.
If usleep(5) is called the call takes 60µs, the ~55µs is always added on top.
I have checked if this is just an overhead for a function but it cannot be reproduced with e.g. a
sqlite3 call (those are sub 3µs).
The overhead was a bit lower on different platforms with different PHP versions, but still very
present.
These numbers are from a machine with a AMD Ryzen 7 3700X 8-Core Processor.
3v4l.org link: https://3v4l.org/laINg#v8.1.5 (I have
lowered the $revs due to timeout).
The following code:
```php
<?php
$revs = 1000000;
$time_start = microtime(true);
for ($n=0; $n<$revs; $n++) {
usleep(0);
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "$time seconds\n";
$ops = ($time * 1000 * 1000) / $revs;
echo "$ops op/microsecond";
```
Resulted in this output:
```
54.799515008926 seconds
54.799515008926 op/microsecond
```
But I expected this output instead (or similar):
```
0.76021695137024 seconds
0.76021695137024 op/microsecond
```
### PHP Version
PHP 8.1.5
### Operating System
Debian