Advertisement
teknoraver

ctx.c

Feb 9th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <stdint.h>
  6. #include <string.h>
  7. #include <limits.h>
  8. #include <x86intrin.h>
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.     unsigned junk;
  13.     unsigned long long time;
  14.     int i;
  15.     int min = INT_MAX;
  16.  
  17.     for (i = 0; i < 10000000; i++) {
  18.         time = __rdtscp(&junk);
  19.         syscall(-1L);
  20.         time = __rdtscp(&junk) - time;
  21.         if (time < min)
  22.             min = time;
  23.     }
  24.     printf("ctx cycles: %d\n", min);
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement