Guest User

Untitled

a guest
Feb 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <sched.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. static long nanotime() {
  6. struct timespec tp;
  7. clock_gettime(CLOCK_MONOTONIC, &tp);
  8. return tp.tv_sec * 1000000000L + tp.tv_nsec;
  9. }
  10.  
  11. static void measure_yield() {
  12. long times[10];
  13. int i;
  14.  
  15. for (i = 0; i < 10; i++) {
  16. long start_time = nanotime();
  17. sched_yield();
  18. times[i] = nanotime() - start_time;
  19. }
  20.  
  21. printf("[%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld]\n",
  22. times[0], times[1], times[2], times[3], times[4],
  23. times[5], times[6], times[7], times[8], times[9]);
  24. }
  25.  
  26. int main() {
  27. int i;
  28. for (i = 0; i < 10; i++) {
  29. measure_yield();
  30. }
  31. return 0;
  32. }
Add Comment
Please, Sign In to add comment