Open
Description
On linux, Instant uses clock_gettime with CLOCK_MONOTONIC which does not count time spent in a sleep state such as hiberation or standby.
On Windows, Instant uses QueryPerformanceCounter which does count time spent in a sleep state:
QueryPerformanceCounter reads the performance counter and returns the total number of ticks that have occurred since the Windows operating system was started, including the time when the machine was in a sleep state such as standby, hibernate, or connected standby.
Neither behavior is currently documented.
Consider the following code (adapted from similar code in Tokio):
use std::time::{Duration, SystemTime, Instant};
fn main() {
let mut next = Instant::now();
loop {
let now = Instant::now();
if next > now {
std::thread::sleep(next - now);
}
next += Duration::from_secs(1);
println!("{:?} tick", SystemTime::UNIX_EPOCH.elapsed().unwrap().as_millis());
}
}
Behavior on Linux: Ticks during sleep are lost.
Behavior on Windows: Ticks during sleep occur in rapid succession after resume.