Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
darwin: invoke mach_timebase_info only once
Browse files Browse the repository at this point in the history
According to @aktau, the call to `mach_timebase_info` costs 90% of the
total execution time of `uv_hrtime()`. The result of the call is static
on all existing platforms, so there is no need in invoking it multiple
times.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
indutny committed Jun 24, 2014
1 parent 58f8769 commit 211bf4e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/unix/darwin.c
Expand Up @@ -179,12 +179,14 @@ void uv__cf_loop_signal(uv_loop_t* loop, cf_loop_signal_cb cb, void* arg) {


uint64_t uv__hrtime(void) {
mach_timebase_info_data_t info;
static mach_timebase_info_data_t info;

if (mach_timebase_info(&info) != KERN_SUCCESS)
abort();
if ((ACCESS_ONCE(uint32_t, info.numer) == 0 ||
ACCESS_ONCE(uint32_t, info.denom) == 0) &&
mach_timebase_info(&info) != KERN_SUCCESS)
abort();

return mach_absolute_time() * info.numer / info.denom;
return mach_absolute_time() * info.numer / info.denom;
}


Expand Down

0 comments on commit 211bf4e

Please sign in to comment.