Skip to content

Instantly share code, notes, and snippets.

@benwaffle
Created August 1, 2014 20:42
Show Gist options
  • Save benwaffle/f95382d744fde1d959a2 to your computer and use it in GitHub Desktop.
Save benwaffle/f95382d744fde1d959a2 to your computer and use it in GitHub Desktop.
rdtsc demo
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
inline uint64_t rdtsc() {
uint32_t low, high;
__asm__ __volatile__("rdtsc" : "=a"(low), "=d"(high));
return (uint64_t)low | ((uint64_t)high << 32);
}
int main() {
fork();
uint64_t count = rdtsc();
for (int i = 0; i < 100000; ++i)
usleep(1);
printf("%d: %llu\n", getpid(), rdtsc() - count);
}
all:
gcc -std=c99 -O1 main.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment