Created
January 30, 2016 12:56
-
-
Save coderodde/84c7596b9136712f80af to your computer and use it in GitHub Desktop.
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 <stdint.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
uint64_t read_time_stamp_counter() | |
{ | |
uint32_t my_edx; | |
uint32_t my_eax; | |
asm ("cpuid\n\t" | |
"rdtsc\n\t" | |
"movl %%edx, %0\n\t" | |
"movl %%eax, %1" | |
:"=r"(my_edx), "=r"(my_eax) | |
: | |
: "%eax", "%edx"); | |
return (((uint64_t) my_edx) << 32) | my_eax; | |
} | |
int main(int argc, char** argv) { | |
uint64_t time_stamp_1 = read_time_stamp_counter(); | |
sleep(1); | |
uint64_t cycles = read_time_stamp_counter() - time_stamp_1; | |
printf("Cycles: %llu\n", cycles); | |
printf("Estimated frequency: %.3f GHz\n", cycles / 1e9); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment