Skip to content
Myr

Initial windows timing support

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Steve Pentland · committed by sharkdp · parent 92a0d4c · Browse files · 4 files+50 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+50 added−2 removed

  • other:+50 added−2 removed

4 files+50 added−2 removed

modified:src/hyperfine/timer/cputimer.rs+43 added-2 removed
43 unmodified lines
4445/// Read CPU execution times (dummy for now)46#[cfg(windows)]47fn get_cpu_times() -> CPUTimes {48 use winapi::um::processthreadsapi::{GetCurrentProcess, GetProcessTimes};49 use winapi::shared::minwindef::FILETIME;5051 // Winapi reports times as per 100 nanosecond52 const HUNDRED_NS_PER_MS: i64 = 10;53 let mut _ctime = FILETIME {54 dwLowDateTime: 0,55 dwHighDateTime: 0,56 };57 let mut _etime = FILETIME {58 dwLowDateTime: 0,59 dwHighDateTime: 0,60 };61 let mut kernel_time = FILETIME {62 dwLowDateTime: 0,63 dwHighDateTime: 0,64 };65 let mut user_time = FILETIME {66 dwLowDateTime: 0,67 dwHighDateTime: 0,68 };6970 let (user_usec, system_usec) = unsafe {71 let handle = GetCurrentProcess();72 let res = GetProcessTimes(73 handle,74 &mut _ctime,75 &mut _etime,76 &mut kernel_time,77 &mut user_time,78 );79 // Extract times as laid out here: https://support.microsoft.com/en-us/help/188768/info-working-with-the-filetime-structure80 if res != 0 {81 let user: i64 = (((user_time.dwHighDateTime as i64) << 32) + user_time.dwLowDateTime as i64) / HUNDRED_NS_PER_MS;82 let kernel: i64 = (((kernel_time.dwHighDateTime as i64) << 32) + kernel_time.dwLowDateTime as i64) / HUNDRED_NS_PER_MS;83 (user, kernel)84 } else {85 (0, 0)86 }87 };8889 CPUTimes {49 user_usec: 0,50 system_usec: 0,90 user_usec,91 system_usec,92 }93}9495/// Compute the time intervals in between two `CPUTimes` snapshots
52 unmodified lines
modified:src/main.rs+3 added
6 unmodified lines
78#[cfg(not(target_os = "windows"))]9extern crate libc;1011#[cfg(target_os = "windows")]12extern crate winapi;1314#[cfg(test)]15#[macro_use]16extern crate approx;17
150 unmodified lines
modified:Cargo.lock+1 added
102 unmodified lines
103 "colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",104 "indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",105 "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",106 "statistical 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",107 "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",108]109110[[package]]111name = "indicatif"
353 unmodified lines
modified:Cargo.toml+3 added