Re: Fastest way to replace characters in string
Re: Fastest way to replace characters in string
- Subject: Re: Fastest way to replace characters in string
- From: Marcel Weiher <email@hidden>
- Date: Thu, 22 Aug 2013 20:50:39 +0200
On Aug 22, 2013, at 19:43 , Steve Mills <email@hidden> wrote:
> On Aug 22, 2013, at 12:31:55, Thomas Wetmore <email@hidden>
> wrote:
>
>> Pre-allocation doesn't really matter as long as the re-allocations, whenever they occur, respect the capacity argument.
>
> Sure they do. If you don't preallocate, but instead keep appending, and the pointer needs to grow with every append, it *could* reallocate with every append.
But that’s not how it’s typically implemented, you usually get some sort of exponential growth ( 2x or optimally something around 1.5x ), so amortized re-allocation cost on growth tends to be dominated by other factors. Using the NSData variant of the algorithm I presented earlier and averaging over 4 runs each, I get a 2.5% difference. Considering the factor 10-50 or more from the other optimizations, that’s pretty negligible, and was also significantly less than the variance between runs (so we would need a whole lot more runs to see whether the difference is actually real, chances are it isn’t).
Despite the fact that I am somewhat performance-obsessed, I tend to not pre-allocate.
Cheers,
Marcel
_______________________________________________
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