Last active
August 27, 2018 08:05
-
-
Save cxjwin/b48e1bf7c5c3681bf453df750fbeb0c2 to your computer and use it in GitHub Desktop.
mach_absolute_time()
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 <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