1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
//! This crate allows you to read the x86 timestamp counter (TSC) //! for when you require very low overhead time measurements. //! //! Unlike other crates, this one does not require nightly Rust as it //! uses `cc` instead of inline asm - at the cost of an additional //! `call`+`ret` on every invocation. mod ffi { extern "C" { pub fn rdtsc() -> u64; } } /// Simply invoke `rdtsc` and return the result. #[inline(always)] pub fn rdtsc() -> u64 { unsafe { ffi::rdtsc() } } #[cfg(test)] mod tests { use super::*; #[test] fn it_works() { let a = rdtsc(); let b = rdtsc(); assert!(a < b); } }