Last active
April 5, 2018 22:03
-
-
Save ashafq/d5440f795f29f27649f61c76bf1d9722 to your computer and use it in GitHub Desktop.
Works on rustc 1.27.0-nightly (fb44b4c0e 2018-04-04)
This file contains hidden or 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
#![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