Skip to content

Instantly share code, notes, and snippets.

@jayeye
Created February 27, 2018 05:00
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 jayeye/d38764ee64329c6767c6c03984a5b3e5 to your computer and use it in GitHub Desktop.
Save jayeye/d38764ee64329c6767c6c03984a5b3e5 to your computer and use it in GitHub Desktop.
demonstrate high-res timers
#include <stdio.h>
#include <time.h>
const int kSamples = 16;
int main(int argc, char* argv[]) {
struct timespec t[kSamples];
for (int i = 0; i < kSamples; ++i) {
clock_gettime(CLOCK_REALTIME, &t[i]);
}
printf("0: %ld %ld\n", t[0].tv_sec, t[0].tv_nsec);
for (int i = 1; i < kSamples; ++i) {
printf("%ld\n", t[i].tv_nsec - t[i - 1].tv_nsec +
1000000000L * (t[i].tv_sec - t[i - 1].tv_sec));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment