Skip to content

Instantly share code, notes, and snippets.

@akx
Created September 14, 2020 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akx/81733fe0a5bda30203891bd87b90cb2d to your computer and use it in GitHub Desktop.
Save akx/81733fe0a5bda30203891bd87b90cb2d to your computer and use it in GitHub Desktop.
#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