Skip to content

Conversation

@alexheretic
Copy link
Owner

@alexheretic alexheretic commented Jan 2, 2024

  • Use a high resolution waitable timer when available (>= Windows 10, version 1803).
  • Replace winapi with windows-sys dependency.

The mean sleep accuracy is much better, but occasionally high-res waits still take ~1ms :(

$ cargo run --bin native_sleep_accuracy --release
==> sleep 1ns
average: 2.0µs, best: 1.3µs, worst: 13.9µs
==> sleep 1µs
average: 446.7µs, best: 2.3µs, worst: 725.8µs
==> sleep 1ms
average: 1.775ms, best: 1.502ms, worst: 2.012ms

Performance is poor under high load.

$ cargo run --bin native_sleep_accuracy --release -- load
Simulating 16 thread load
==> sleep 1ns
average: 39.3µs, best: 1.8µs, worst: 36.8ms
==> sleep 1µs
average: 14.9ms, best: 2.1µs, worst: 46.9ms
==> sleep 1ms
average: 16.025ms, best: 2.004ms, worst: 30.071ms

But this was also true before, this should be an improvement overall.

resolves #16

@alexheretic alexheretic merged commit 2204c10 into master Jan 2, 2024
@alexheretic alexheretic deleted the win-high-res-waitable-timer branch January 2, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Windows WaitableTimer with high resolution if available

1 participant