On 7/31/2013 1:01 PM, "Greg Parker" <gpar...@apple.com> wrote:


>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.)
>

Yeah, those numbers make sense from a "theoretical" standpoint (i.e.
without looking at the source code).  The +new call theoretically calls
+alloc/-init so would be slightly slower due to three method calls
(+new/+alloc/-init) and the -init call theoretically can do very little
until actual data is supplied while the others with actual data might add
the overhead of defining the actual data; theoretically, an empty string
is more data than no data yet to be filled.
--
Gary L. Wade
http://www.garywade.com/



_______________________________________________

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