Skip to content

Instantly share code, notes, and snippets.

@sighingnow
Created October 1, 2016 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sighingnow/3f07e028ae7e0b51ef5fa57cb1f8f1ab to your computer and use it in GitHub Desktop.
Save sighingnow/3f07e028ae7e0b51ef5fa57cb1f8f1ab to your computer and use it in GitHub Desktop.
Demo of Read Time-Stamp Counter (rdstc instruction).
/**
* author: Tao He, sighingnow@gmail.com
*/
uint64_t rdtsc() {
uint32_t lo, hi;
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
return (uint64_t)hi << 32 | lo;
}
int main(int, char **) {
printf("%llu\n", rdtsc());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment