#import "ViewController.h"
#import <UIKit/UIKit.h>
#import <mach/mach_time.h> //要使用统计程序执行时间的函数,必须导入的头文件
#import <Foundation/Foundation.h>
@interface ViewController ()
@property(nonatomic,copy) NSString *nonatomicTest;
@property(atomic,copy) NSString *atomicTest;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
uint64_t start = mach_absolute_time();
self.nonatomicTest = @"test";
uint64_t end = mach_absolute_time();
NSLog(@"end - begin = %llu",end-start);
uint64_t start1 = mach_absolute_time();
self.atomicTest = @"test";
uint64_t end1 = mach_absolute_time();
NSLog(@"end1 - begin1 = %llu",end1-start1);
//通过测试可以看出当声明为nonatomic,系统执行时能提高几倍的效率,所以在属性声明的时候,当该成员不会在多线程下访问时,尽量将它声明为为非原子性
}