Re: Initializing a NSMutableString an odd way
Re: Initializing a NSMutableString an odd way
- Subject: Re: Initializing a NSMutableString an odd way
- From: Alex Zavatone <email@hidden>
- Date: Wed, 31 Jul 2013 16:43:52 -0400
On Jul 31, 2013, at 4:01 PM, Greg Parker wrote:
> 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.
I'm rather fascinated with these and wrote the one that profiled the speed of all variable classes and functions of Lingo back in the Director days.
Once we knew just how fast each of the variable allocations and functions took when compared to each other, this made it really easy to determine what approaches not to use in the interests of performance, or where we could change code for the sake of readability over performance.
By any chance is this harness open or is it a private project? Of course, we have instruments, but it would be rather great to simply be able to plug in some operations and know the speed of them and their speed relative to each other.
> 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
>
Your note got cut off near the en
_______________________________________________
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