Created
September 14, 2020 14:22
-
-
Save akx/81733fe0a5bda30203891bd87b90cb2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
static uint64_t usecdiff(struct timeval *a, struct timeval *b) { | |
uint64_t sec_diff = b->tv_sec - a->tv_sec; | |
uint64_t usec_diff = b->tv_usec - a->tv_usec; | |
return sec_diff * 1000000 + usec_diff; | |
} | |
int main() { | |
struct timeval start, curr; | |
gettimeofday(&start, NULL); | |
for (;;) { | |
gettimeofday(&curr, NULL); | |
uint64_t diff = usecdiff(&start, &curr); | |
start = curr; | |
printf("%llu\n", diff); | |
usleep(1000000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment