Created
August 18, 2014 01:08
-
-
Save benwaffle/3bd3c3b3d059c919b3a4 to your computer and use it in GitHub Desktop.
clock drift
This file contains 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
#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