Skip to content

Instantly share code, notes, and snippets.

@benwaffle
Created August 18, 2014 01:08
Show Gist options
  • Save benwaffle/3bd3c3b3d059c919b3a4 to your computer and use it in GitHub Desktop.
Save benwaffle/3bd3c3b3d059c919b3a4 to your computer and use it in GitHub Desktop.
clock drift
#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() {
int parent = fork();
int i;
uint64_t start = rdtsc();
for(i = 0; i < 20; ++i){
printf("%s%lu\n", parent ? "\t\t" : "" , rdtsc() - start);
fflush(stdout);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment