mach_absolute_time 获取系统运行时间 及 测试代码效率

返回值均为毫秒

ios  

#include <mach/mach_time.h>

 

uint64_t time = mach_absolute_time();

    mach_timebase_info_data_t timebase;

    mach_timebase_info(&timebase);

    return (double)time * (double)timebase.numer /

    (double)timebase.denom / 1e6;

 

mac 

 

#include <CoreServices/CoreServices.h>

#include <mach/mach_time.h>

 

Nanoseconds timeNano;

    uint64_t time = mach_absolute_time();

    timeNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &time);

return  (* (uint64_t *)&timeNano) / 1000000 ;

 

你可能感兴趣的:(absolute)