Re: Repetitive Appending of Strings
Re: Repetitive Appending of Strings
- Subject: Re: Repetitive Appending of Strings
- From: "Michael Ash" <email@hidden>
- Date: Tue, 12 Feb 2008 13:22:55 -0500
On Feb 12, 2008 11:47 AM, Andrew Merenbach <email@hidden> wrote:
> Note that call to -appendFormat. This is a beautiful solution in
> terms of simplicity, but for long outputs it's calling a method
> repeatedly.
>
> What are my options here? The most simple optimization would involve
> using an IMP and creating a function pointer to a method, yes?
>
> Are there, however, other options available, ones that might be
> better? For example, would it be more efficient (I'd imagine that it
> would be) if I malloc'ed, or NSZoneMalloc'ed, a unichar pointer and
> then used -initWithCharacters:length: or -
> initWithCharactersNoCopy:length:freeWhenDone:?
An Objective-C message send takes on the order of a dozen cycles to
execute. Put it another way, on any Mac you can buy today, an
Objective-C message will take less than ten *nanoseconds* to complete.
Unless you're outputting a ridiculously large number of digits, and
you've actually measured the code and determined that this is where
the problem is, it's simply not worth worrying about.
It's tempting to fret about Objective-C messages because they appear
to do so much, but they're ridiculously fast and it almost never pays
to try to avoid them.
Mike
_______________________________________________
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