• 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: Fastest way to replace characters in string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Fastest way to replace characters in string (From: Diederik Meijer | Ten Horses <email@hidden>)
 >Re: Fastest way to replace characters in string (From: Wim Lewis <email@hidden>)
 >Re: Fastest way to replace characters in string (From: Diederik Meijer | Ten Horses <email@hidden>)
 >Re: Fastest way to replace characters in string (From: Jens Alfke <email@hidden>)
 >Re: Fastest way to replace characters in string (From: Keary Suska <email@hidden>)
 >Re: Fastest way to replace characters in string (From: Thomas Wetmore <email@hidden>)
 >Re: Fastest way to replace characters in string (From: Steve Mills <email@hidden>)

  • Prev by Date: Re: Issues with NSTextView Attachments
  • Next by Date: Re: Issues with NSTextView Attachments
  • Previous by thread: Re: Fastest way to replace characters in string
  • Next by thread: Re: Fastest way to replace characters in string
  • Index(es):
    • Date
    • Thread