iOS检测代码执行效率

RT

#import <mach/mach_time.h>

double MachTimeToSecs(uint64_t time)

{

    mach_timebase_info_data_t timebase;

    mach_timebase_info(&timebase);

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

    (double)timebase.denom /1e9;

}

- (void)doSomething

{

    uint64_t beginTime = mach_absolute_time();

    // 在这里放置你要检测效率的代码

    uint64_t endTime = mach_absolute_time();

    NSLog(@"Time taken to doSomething %g s",MachTimeToSecs(endTime - beginTime));

}


你可能感兴趣的:(ios,效率,执行时间)