函数功能是可以用来测量程序当前执行这条语句的时间,从而可以判断效率是否高
CFAbsoluteTImeGetCurrent();
得到当前绝对时间
例:
NSMutableArray *test = [NSMutableArray array];
for (int i= 0; i < 10000000; i++) {
[test addObject:@(i)];
}
int sum = 0;
double date_s = CFAbsoluteTimeGetCurrent();
for (int i = 0;i < test.count; i++) {
sum += 1;
}
double date_e = CFAbsoluteTimeGetCurrent();
NSLog(@"ForLoop Time: %f", date_e - date_s);
date_s = CFAbsoluteTimeGetCurrent();
for (id obj in test) {
sum += 1;
}
date_e = CFAbsoluteTimeGetCurrent();
NSLog(@"Enumeration Time: %f", date_e - date_s);
测试结果: