rdtsc.c 463 B

1234567891011121314151617181920212223242526
  1. /*
  2. Only works in x86_64.
  3. - https://en.wikipedia.org/wiki/Time_Stamp_Counter
  4. - https://stackoverflow.com/questions/9887839/clock-cycle-count-wth-gcc/9887979
  5. */
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #if defined(__i386__) || defined(__x86_64__)
  10. #include <x86intrin.h>
  11. #endif
  12. int main(void) {
  13. uintmax_t val;
  14. #if defined(__i386__) || defined(__x86_64__)
  15. val = __rdtsc();
  16. #else
  17. val = 0;
  18. #endif
  19. printf("%ju\n", val);
  20. return EXIT_SUCCESS;
  21. }