为什么非原子属性比原子属性快
这是我的代码:
@interface ViewController ()
@property(atomic, assign) NSInteger a;
@property(nonatomic, assign) NSInteger b;
@end
@implementation ViewController
(void)viewDidLoad {
[super viewDidLoad];
CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
for (NSInteger i = 0; i < 100000; i++) {
self.a = i;
}
CFAbsoluteTime time = (CFAbsoluteTimeGetCurrent() - startTime);
NSLog(@"atomic %f ms", time * 1000.0);
startTime = CFAbsoluteTimeGetCurrent();
for (NSInteger i = 0; i < 100000; i++) {
self.b = i;
}
time = (CFAbsoluteTimeGetCurrent() - startTime);
NSLog(@"nonatomic in %f ms", time * 1000.0);
}
@end`
有人可以帮我解决这个问题吗?