Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <sys/time.h> // первый вариант gettimeofday
- #include <time.h> // второй вариант clock_gettime
- int main()
- {
- struct timeval stop, start;
- gettimeofday(&start, NULL);
- struct timespec start1, stop1;
- clock_gettime(CLOCK_MONOTONIC_RAW, &start1); // можно такCLOCK_MONOTONIC_RAW и так можно CLOCK_REALTIME
- printf("Hello World!n");
- int a = 1000;
- for (int i =0; i<a;i++)
- printf("%d n",i);
- gettimeofday(&stop, NULL);
- printf("took %lun", stop.tv_usec - start.tv_usec);
- printf("------------------ n");
- clock_gettime(CLOCK_MONOTONIC_RAW, &stop1); // можно такCLOCK_MONOTONIC_RAW и так можно CLOCK_REALTIME
- uint64_t delta_us = (stop1.tv_sec - start1.tv_sec) * 1000000 + (stop1.tv_nsec - start1.tv_nsec) / 1000;
- printf("delta_us = %d n", delta_us);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement