プロパティのatomicとnonatomic

Objective-Cプロパティの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];
    id x[2];
    x[0] = [[[NSObject alloc] init] autorelease];
    x[1] = [[[NSObject alloc] init] autorelease];

    for(unsigned long i = 0; i < 100000000; i++) {
        test.obj = x[i%2];
    }
    
    [pool release];
    return 0;
}       
            
@implementation Test01
@synthesize obj;
@end

@implementation Test02
@synthesize obj;
@end
#nonatomic
MBP:~/tmp/src masaki$ time ./test 0

real    0m10.101s
user    0m9.306s
sys    0m0.029s

#atomic
MBP:~/tmp/src masaki$ time ./test 1

real    0m12.929s
user    0m11.809s
sys    0m0.034s

atomicなセッタはnonatomicのそれより26%増し。
割とでかい。