Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/time.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- /* Return 1 if the difference is negative, otherwise 0. */
- int timeval_subtract(struct timeval *result, struct timeval *t2, struct timeval *t1)
- {
- long int diff = (t2->tv_usec + 1000000 * t2->tv_sec) - (t1->tv_usec + 1000000 * t1->tv_sec);
- result->tv_sec = diff / 1000000;
- result->tv_usec = diff % 1000000;
- return (diff<0);
- }
- int main()
- {
- struct timeval tvBegin, tvEnd, tvDiff;
- gettimeofday(&tvBegin, NULL);
- yourFunction();
- gettimeofday(&tvEnd, NULL);
- // разница
- timeval_subtract(&tvDiff, &tvEnd, &tvBegin);
- printf("%ld.%06ld\n", tvDiff.tv_sec, tvDiff.tv_usec);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement