Sleep not even close to millisecond granularity? #4473
-
I think I am maybe missing something obvious. The docs suggest sleep has millisecond granularity (docs here), but here is a very simple program and output (running Windows 10): #[tokio::main]
async fn main() {
let now = tokio::time::Instant::now();
for _ in 0..5 {
tokio::time::sleep(Duration::from_millis(10)).await;
println!("{:?}", now.elapsed());
}
} Example output from running above code:
The elapsed times seems wildly wrong - I would expect numbers to be closer to 10, 20, 30, 40, 50. I read "millisecond granularity" to suggest plus or minus 1ms but I am seeing 24ms when I expect 10ms. Also the sleep time is always much greater than 10ms, so it's not just an initial startup/jitter. Is this the expected behavior? Example output when increasing duration to
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Windows's sleep granularity is something like ~16 milliseconds IIRC. |
Beta Was this translation helpful? Give feedback.
Windows's sleep granularity is something like ~16 milliseconds IIRC.