• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Initializing a NSMutableString an odd way
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Initializing a NSMutableString an odd way


  • Subject: Re: Initializing a NSMutableString an odd way
  • From: "Gary L. Wade" <email@hidden>
  • Date: Wed, 31 Jul 2013 13:14:52 -0700
  • Thread-topic: Initializing a NSMutableString an odd way

On 7/31/2013 1:01 PM, "Greg Parker" <email@hidden> 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 (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


References: 
 >Re: Initializing a NSMutableString an odd way (From: Greg Parker <email@hidden>)

  • Prev by Date: Re: Initializing a NSMutableString an odd way
  • Next by Date: Re: Initializing a NSMutableString an odd way
  • Previous by thread: Re: Initializing a NSMutableString an odd way
  • Next by thread: Re: Initializing a NSMutableString an odd way
  • Index(es):
    • Date
    • Thread