获取代码的执行时间

如何获取一段代码的执行时间:

 id object = @"ss";
CFTimeInterval startTime = CACurrentMediaTime();
{
    for (size_t i = 0; i< 1000; i++) {
        @autoreleasepool {
            NSMutableArray * mutableArray = [NSMutableArray array];
            for (size_t j = 0; j < 1000; j++) {
                [mutableArray addObject:object];
            }
        }
    }
}
CFTimeInterval endTime = CACurrentMediaTime();
NSLog(@"Total Runtime = %g s",endTime - startTime);

你可能感兴趣的:(获取代码的执行时间)