Created
December 22, 2019 02:32
-
-
Save oconnor663/06206df07fa48457901220008b66cb8b to your computer and use it in GitHub Desktop.
sampling what rdtsc reports for the clock frequency (often wrong)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn ticks() -> u64 { | |
let mut discard = 0; | |
unsafe { core::arch::x86_64::__rdtscp(&mut discard) } | |
} | |
fn main() { | |
let t0 = std::time::Instant::now(); | |
let c0 = ticks(); | |
std::thread::sleep(std::time::Duration::from_secs(1)); | |
let t1 = std::time::Instant::now(); | |
let c1 = ticks(); | |
let t_diff = t1 - t0; | |
let c_diff = c1 - c0; | |
dbg!(t_diff); | |
dbg!(c_diff); | |
let ghz = c_diff as f64 / t_diff.as_nanos() as f64; | |
dbg!(ghz); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment