Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Nov 9, 2019
1 parent eee9a61 commit c5c4f8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/manifest.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <semaphore.h>
#include <pthread.h>

#include "misc/timing.h"
#include "misc/macros.h"
#include "misc/notify.h"
#include "misc/log.h"
Expand Down
29 changes: 29 additions & 0 deletions src/misc/timing.h
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);
}

0 comments on commit c5c4f8f

Please sign in to comment.