darwin: invoke mach_timebase_info only once

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>
This commit is contained in:
Fedor Indutny 2014-06-19 11:27:24 -04:00
parent 58f87691a4
commit 211bf4ec37

View File

@ -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;
}