Skip to content

Commit fbd429e

Browse files
committed
diag: Windows usleep(1000) duration
0 parents  commit fbd429e

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎.github/workflows/diag.yml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: diag-windows-usleep
2+
on: push
3+
jobs:
4+
usleep:
5+
runs-on: windows-2022
6+
defaults: { run: { shell: bash } }
7+
steps:
8+
- uses: shivammathur/setup-php@v2
9+
with: { php-version: "8.4", phpts: zts, extensions: ffi }
10+
- name: usleep(1000) against the millisecond wall clock
11+
run: |
12+
cat > d.php <<'PHP'
13+
<?php
14+
function run(string $label): void {
15+
$n = 5000; $same = 0; $min = PHP_INT_MAX; $under = 0;
16+
for ($i = 0; $i < $n; $i++) {
17+
$a = (int) (microtime(true) * 1000); $h = hrtime(true);
18+
usleep(1000);
19+
$e = hrtime(true) - $h; $b = (int) (microtime(true) * 1000);
20+
$min = min($min, $e); if ($e < 1_000_000) $under++; if ($a === $b) $same++;
21+
}
22+
printf("%s: %d/%d usleep(1000) under 1 ms (min %.3f ms), %d with the same millisecond before and after\n", $label, $under, $n, $min / 1e6, $same);
23+
}
24+
run('default timer resolution');
25+
$w = FFI::cdef('unsigned int timeBeginPeriod(unsigned int);', 'winmm.dll');
26+
$w->timeBeginPeriod(1);
27+
run('timeBeginPeriod(1) (as mongod sets it)');
28+
PHP
29+
php d.php

0 commit comments

Comments
 (0)