Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <sys/time.h> // первый вариант gettimeofday
  4. #include <time.h> // второй вариант clock_gettime
  5.  
  6. int main()
  7. {
  8. struct timeval stop, start;
  9. gettimeofday(&start, NULL);
  10.  
  11. struct timespec start1, stop1;
  12. clock_gettime(CLOCK_MONOTONIC_RAW, &start1); // можно такCLOCK_MONOTONIC_RAW и так можно CLOCK_REALTIME
  13.  
  14. printf("Hello World!n");
  15. int a = 1000;
  16. for (int i =0; i<a;i++)
  17. printf("%d n",i);
  18.  
  19. gettimeofday(&stop, NULL);
  20. printf("took %lun", stop.tv_usec - start.tv_usec);
  21. printf("------------------ n");
  22.  
  23. clock_gettime(CLOCK_MONOTONIC_RAW, &stop1); // можно такCLOCK_MONOTONIC_RAW и так можно CLOCK_REALTIME
  24. uint64_t delta_us = (stop1.tv_sec - start1.tv_sec) * 1000000 + (stop1.tv_nsec - start1.tv_nsec) / 1000;
  25. printf("delta_us = %d n", delta_us);
  26.  
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement