Skip to content

Instantly share code, notes, and snippets.

@cxjwin
Last active August 27, 2018 08:05
Show Gist options
  • Save cxjwin/b48e1bf7c5c3681bf453df750fbeb0c2 to your computer and use it in GitHub Desktop.
Save cxjwin/b48e1bf7c5c3681bf453df750fbeb0c2 to your computer and use it in GitHub Desktop.
mach_absolute_time()
#include <mach/mach_time.h>
/* Get the timebase info */
mach_timebase_info_data_t info;
mach_timebase_info(&info);
uint64_t start = mach_absolute_time();
/* Do some code */
uint64_t duration = mach_absolute_time() - start;
/* Convert to nanoseconds */
duration *= info.numer;
duration /= info.denom;
/* Log the time */
NSLog(@"My amazing code took %lld nanoseconds!", duration);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment