Created
January 3, 2019 07:08
-
-
Save ymyzk/004d088d64453c12788bcc11976936ab to your computer and use it in GitHub Desktop.
Using mach_absolute_time to get precise/monotonic clock
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 <inttypes.h> | |
#include <mach/mach_time.h> | |
#include <stdio.h> | |
int main(void) { | |
static mach_timebase_info_data_t timebase; | |
mach_timebase_info(&timebase); | |
uint64_t time = mach_absolute_time(); | |
printf("mach_absolute_time: %" PRIu64 "\n", time); | |
printf("resolution: %f\n", (double)timebase.numer / (double)timebase.denom); | |
printf("time in ns: %" PRIu64 "\n", time * timebase.numer / timebase.denom); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment