iOS代码耗时统计

·  阅读 314

使用内核滴答时间统计最为精准,详细参考Quick Performance Measurements

#import <mach/mach_time.h> // for mach_absolute_time
 
double MachTimeToSecs(uint64_t time)
{
    mach_timebase_info_data_t timebase;
    mach_timebase_info(&timebase);
    return (double)time * (double)timebase.numer / 
    (double)timebase.denom / NSEC_PER_SEC;
}
    
- (void)profileDoSomething
{  
    uint64_t begin = mach_absolute_time();
    [self doSomething];
    uint64_t end = mach_absolute_time();
    NSLog(@"Time taken to doSomething %g s", 
    MachTimeToSecs(end - begin));
}
复制代码
分类:
iOS
标签:
收藏成功!
已添加到「」, 点击更改