プロパティのatomicとnonatomic 再び
昨日セッタしか比べなかったので、今日はゲッタ。
#import <Foundation/Foundation.h> @interface Test01 : NSObject @property (nonatomic,retain) id obj; @end @interface Test02 : NSObject @property (retain) id obj; @end int main( int argc, char *argv[]) { id pool = [[NSAutoreleasePool alloc] init]; if(argc<2) return -1; int type = atoi(argv[1]); Class aClass = NULL; switch(type) { case 0: aClass = [Test01 class]; break; case 1: aClass = [Test02 class]; break; } if(!aClass) return -1; Test01 *test = [[[aClass alloc] init] autorelease]; test.obj = @""; id x[2]; for(unsigned long i = 0; i < 100000000; i++) { x[i%2] = test.obj; } [pool release]; return 0; } @implementation Test01 @synthesize obj; @end @implementation Test02 @synthesize obj; @end
#nonatomic MBP:~/tmp/src masaki$ time ./test 0 real 0m1.034s user 0m1.025s sys 0m0.006s #atomic MBP:~/tmp/src masaki$ time ./test 1 real 0m4.318s user 0m4.292s sys 0m0.008s
4倍超!!!
これはでかい!!