Created
August 1, 2014 20:42
-
-
Save benwaffle/f95382d744fde1d959a2 to your computer and use it in GitHub Desktop.
rdtsc demo
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() { | |
fork(); | |
uint64_t count = rdtsc(); | |
for (int i = 0; i < 100000; ++i) | |
usleep(1); | |
printf("%d: %llu\n", getpid(), rdtsc() - count); | |
} |
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
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