mach_absolute_time
#import <mach/mach_time.h>
//获取Mach时间
uint64_t _startTime = mach_absolute_time();
uint64_t endTime = mach_absolute_time();
NSLog(@"%f", substractTime(endTime, _startTime));
//获取系统的时间基准
double substractTime(uint64_t endTime, uint64_t startTime) {
uint64_t difference = endTime - startTime;
static double conversion = 0.0;
if (conversion == 0.0) {
mach_timebase_info_data_t info;
//mach_timebase_info() 获取时间基准info结构体
kern_return_t err = mach_timebase_info(&info);
if (err == 0 ) {
//用结构体中的分子项/分母项 即为时间基准
//乘以1e-9获取秒级别(1e-9即为1纳秒)
conversion= 1e-9 * (double) info.numer / (double) info.denom;
}
}
return conversion * (double)difference;;
}