On 31.07.2013, at 22:01, Greg Parker <gpar...@apple.com> wrote:

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


How much time contributes the allocation of the raw storage? I would guess that 
initializing an empty string is quite fast (while generally NSString is 
disappointing slow in almost all other functions).

What's also interesting is the time it takes to *deallocate* an object. Since 
ARC and weak pointers, this time increased dramatically (due to the requirement 
to remove the object from the "sparse array").


In those micro-benchmarks its also interesting how this benchmark affects the 
behavior of the heap. It's likely we see a particular edge case which is either 
fast or slow. I would expect that allocating and deallocating the same object 
in a loop leads to faster allocation times. As opposed to the case where 
differrent objects are allocated and deallocated in random order.


Andreas


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