IOS中的精确计时
IOS中可以使用"mach_absolute_time"获取到CPU的tickcount的计数值,可以通过"mach_timebase_info"函数获取到纳秒级的精确度 代码如下: uint64t start = 0; uint64t end = 0; uint64_t elapsed = 0;
mach_timebase_info_t timeBaseInfo = mach_timebase_info(info); start = mach_absolute_time();
// dosomething
// .....
end = mach_absolute_time(); elapsed = end - start;
// convert to nanoseconds
uint64_t elapsedNanoSeconds = elapsed * sTimebaseInfo.numer / sTimebaseInfo.denom;
但是CPU线程之间的调度肯定要花费时间,所以只能尽可能的精确。