-
-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eee9a61
commit c5c4f8f
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <CoreServices/CoreServices.h> | ||
#include <mach/mach_time.h> | ||
|
||
static inline uint64_t time_clock(void) | ||
{ | ||
return mach_absolute_time(); | ||
} | ||
|
||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
static inline uint64_t time_elapsed_ns(uint64_t begin, uint64_t end) | ||
{ | ||
uint64_t elapsed = end - begin; | ||
Nanoseconds nano = AbsoluteToNanoseconds(*(AbsoluteTime *) &elapsed); | ||
return *(uint64_t *) &nano; | ||
} | ||
#pragma clang diagnostic pop | ||
|
||
static inline double time_elapsed_ms(uint64_t begin, uint64_t end) | ||
{ | ||
uint64_t ns = time_elapsed_ns(begin, end); | ||
return (double)(ns / 1000000.0); | ||
} | ||
|
||
static inline double time_elapsed_s(uint64_t begin, uint64_t end) | ||
{ | ||
uint64_t ns = time_elapsed_ns(begin, end); | ||
return (double)(ns / 1000000000.0); | ||
} |