Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <unistd.h>
  4. #include <sys/syscall.h>
  5.  
  6. static int clock_gettime_syscall(clockid_t clk_id, struct timespec *tp)
  7. {
  8. return syscall(__NR_clock_gettime, clk_id, tp);
  9. }
  10.  
  11.  
  12. int main(void)
  13. {
  14. int i;
  15. struct timespec t, start;
  16.  
  17. clock_gettime(CLOCK_REALTIME, &start);
  18. i = 0;
  19. do {
  20. clock_gettime(CLOCK_REALTIME, &t);
  21. i++;
  22. } while (t.tv_sec == start.tv_sec || t.tv_nsec < start.tv_nsec);
  23. printf("vdso hires: %fns\n", 1000000000.0 / i);
  24. clock_gettime(CLOCK_REALTIME_COARSE, &start);
  25. i = 0;
  26. do {
  27. clock_gettime(CLOCK_REALTIME_COARSE, &t);
  28. i++;
  29. } while (t.tv_sec == start.tv_sec || t.tv_nsec < start.tv_nsec);
  30. printf("vdso coarse: %fns\n", 1000000000.0 / i);
  31.  
  32. clock_gettime_syscall(CLOCK_REALTIME, &start);
  33. i = 0;
  34. do {
  35. clock_gettime_syscall(CLOCK_REALTIME, &t);
  36. i++;
  37. } while (t.tv_sec == start.tv_sec || t.tv_nsec < start.tv_nsec);
  38.  
  39. printf("sysc hires: %fns\n", 1000000000.0 / i);
  40. clock_gettime_syscall(CLOCK_REALTIME_COARSE, &start);
  41. i = 0;
  42. do {
  43. clock_gettime_syscall(CLOCK_REALTIME_COARSE, &t);
  44. i++;
  45. } while (t.tv_sec == start.tv_sec || t.tv_nsec < start.tv_nsec);
  46. printf("sysc coarse: %fns\n", 1000000000.0 / i);
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement