Skip to content

Instantly share code, notes, and snippets.

@ymyzk
Created January 3, 2019 07:08
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 ymyzk/004d088d64453c12788bcc11976936ab to your computer and use it in GitHub Desktop.
Save ymyzk/004d088d64453c12788bcc11976936ab to your computer and use it in GitHub Desktop.
Using mach_absolute_time to get precise/monotonic clock
#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