Re: Is checking -count worth it?
Re: Is checking -count worth it?
- Subject: Re: Is checking -count worth it?
- From: Jens Alfke <email@hidden>
- Date: Thu, 24 Jul 2008 10:56:54 -0700
On 24 Jul '08, at 12:02 AM, Matthew Schinckel wrote:
Am I better off in general (ie, adding objects, removing objects,
etc) using an NS(Mutable)Set instead of an NSArray, if I don't need
sorting and duplicate items?
As always, it depends. For the most part, sets are faster because
they're implemented using hash tables. This makes them scale much
better for locating or removing items. But they do have a bit more
fixed overhead per operation, since they have to compute the hash code
of the object. So for very small collections, an array might be
faster. It's also faster to just append an item to an array than to
add it to a set.
Sets also have somewhat higher memory overhead (3 or 4 times
sizeof(id) per item, as opposed to just sizeof(id)).
In reality none of this will matter 99% of the time. It's only
something you want to pay attention to when you're pretty sure that
particular collection will grow huge or be accessed zillions of times.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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