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