On Jul 31, 2013, at 12:28 PM, Vincent Habchi <vi...@macports.org> 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     gpar...@apple.com     Runtime Wrangler



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to