Created
February 27, 2018 05:00
-
-
Save jayeye/d38764ee64329c6767c6c03984a5b3e5 to your computer and use it in GitHub Desktop.
demonstrate high-res timers
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 <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