Guest User

Untitled

a guest
May 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/time.h>
  3.  
  4. #define ILE 50000
  5.  
  6. int main ()
  7. {
  8. int x = 0;
  9. int i = 1;
  10. int j = 0;
  11. struct timeval time;
  12. struct timeval time2;
  13. double miliseconds1 = 0;
  14. double miliseconds2 = 0;
  15.  
  16. for (j = 0; j < ILE; j++)
  17. {
  18. gettimeofday (&time, NULL);
  19. if (x == 0)
  20. i = 0;
  21. else
  22. if (x == 1)
  23. i = 1;
  24. else
  25. if (x == 2)
  26. i = 2;
  27. else
  28. i = 3;
  29. gettimeofday (&time2, NULL);
  30.  
  31. miliseconds1 += time2.tv_usec - time.tv_usec;
  32.  
  33. gettimeofday (&time, NULL);
  34.  
  35. switch (x)
  36. {
  37. case 0: i = 0; break;
  38. case 1: i = 1; break;
  39. case 2: i = 2; break;
  40. default: i = 3;
  41. }
  42.  
  43. gettimeofday (&time2, NULL);
  44. miliseconds2 += time2.tv_usec - time.tv_usec;
  45. }
  46.  
  47. miliseconds1 /= ILE;
  48. miliseconds2 /= ILE;
  49.  
  50. printf ("1: %lf, 2: %lf\n", miliseconds1, miliseconds2);
  51.  
  52.  
  53. return 0;
  54. }
Add Comment
Please, Sign In to add comment