Re: Initializing a NSMutableString an odd way
Re: Initializing a NSMutableString an odd way
- Subject: Re: Initializing a NSMutableString an odd way
- From: Greg Parker <email@hidden>
- Date: Wed, 31 Jul 2013 13:01:10 -0700
On Jul 31, 2013, at 12:28 PM, Vincent Habchi <email@hidden> wrote:
> David Duncan wrote:
>> Why would there be? Your just asking for a mutable copy of an empty string. It should be equivalent to [[NSMutableString alloc] initWithString:@« »]
>
> But much slower I expect, since it creates a NSString, takes a mutable copy, then implicitly releases the constant empty NSString.
For giggles I tried some NSMutableString allocation patterns into my microbenchmark test harness.
Simple alloc/init is the fastest:
100 [[[NSMutableString alloc] init] release]
102 [[NSMutableString new] release]
109 [NSMutableString string] // ARC enabled
117 [[@"" mutableCopy] release]
119 @autoreleasepool { [NSMutableString string]; } // ARC disabled
129 [[[NSMutableString alloc] initWithString:@""] release]
(Smaller numbers are better. Numbers are getrusage(RUSAGE_SELF) time for 10000000 iterations, normalized to fastest=100. Your mileage may vary.)
ARC and non-ARC scores are the same within measurement noise, except for [NSMutableString string] where ARC can optimize the autoreleased return value so the test doesn't need to spin the autorelease pool. Note th
> BTW, what’s the difference between [[NSMutableString alloc] init] and [[NSMutableString alloc] initWithString:@“”]?
Semantically there's no difference: you get the same string with the same retain count.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden