hyperfine
hyperfine copied to clipboard
Fix user and kernel times on Windows
Description
By using a job object and attaching it to the spawned process before launch, we can record the total user and kernel times of it and all of its child processes. Sadly extracting the raw handle of the main_thread_handle
is still nightly only 😢 (see: rust-lang/rust#96723) and required, in order to resume a initially suspended process. Therefore this new CPUTimer implementation is guarded behind a new nightly
cargo feature and not enabled by default.
Example
Before:
> cargo run --quiet -- 'cargo fmt'
Benchmark 1: cargo fmt
Time (mean ± σ): 175.6 ms ± 1.1 ms [User: 0.9 ms, System: 8.4 ms]
Range (min … max): 173.3 ms … 177.3 ms 16 runs
After:
> cargo run --quiet -- 'cargo fmt'
Benchmark 1: cargo fmt
Time (mean ± σ): 175.8 ms ± 1.9 ms [User: 91.5 ms, System: 62.5 ms]
Range (min … max): 173.5 ms … 180.7 ms 16 runs
Fixes: #368