/*
* timing.h
*
* Created by Paolo on 06/07/2007.
* Copyright 2010 Paolo Manna All rights reserved.
*
*/
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <unistd.h>
static mach_timebase_info_data_t timebase = {0, 0};
inline static uint64_t nanosecs()
{
if (timebase.denom == 0)
mach_timebase_info(&timebase);
return (mach_absolute_time() * (uint64_t)(timebase.numer)) / (uint64_t)(timebase.denom);
}
inline static uint64_t usecs()
{
if (timebase.denom == 0)
mach_timebase_info(&timebase);
return (mach_absolute_time() * (uint64_t)(timebase.numer) + 500ULL) / ((uint64_t)(timebase.denom) * 1000ULL);
}
inline static uint64_t msecs()
{
if (timebase.denom == 0)
mach_timebase_info(&timebase);
return (mach_absolute_time() * (uint64_t)(timebase.numer) + 500000ULL) / ((uint64_t)(timebase.denom) * 1000000ULL);
}