Skip to content

Instantly share code, notes, and snippets.

@ashafq
Last active April 5, 2018 22:03
Show Gist options
  • Save ashafq/d5440f795f29f27649f61c76bf1d9722 to your computer and use it in GitHub Desktop.
Save ashafq/d5440f795f29f27649f61c76bf1d9722 to your computer and use it in GitHub Desktop.
Works on rustc 1.27.0-nightly (fb44b4c0e 2018-04-04)
#![feature(asm)]
fn rdtsc() -> u64 {
let eax: u32;
let edx: u32;
unsafe {
asm!("rdtsc; ": /* Assembly */
"={eax}"(eax), "={edx}"(edx) : /* Output registers */
: /* Input registers */
"eax", "edx" /* Clobbers */ );
}
((edx as u64) << 32) | (eax as u64)
}
fn main() {
let start = rdtsc();
println!("Hello, world!");
let stop = rdtsc();
let diff = stop - start;
println!("Took {}", diff);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment