Re: NSArray lookup, pointer comparison
Re: NSArray lookup, pointer comparison
- Subject: Re: NSArray lookup, pointer comparison
- From: Robert Martin <email@hidden>
- Date: Tue, 29 May 2007 14:53:04 -0400
May not be directly relevant, but it's interesting: http://
ridiculousfish.com/blog/archives/2005/12/23/array/
On May 29, 2007, at 1:51 PM, Keith Duncan wrote:
I've searched google for benchmarks but I couldn't find any
specific to what I'm looking for so I decided to do some
benchmarking of my own. | was hoping someone could corroborate or
contradict my results.
I'm iterating over a tree of objects but instead of iterating the
tree multiple times I decided to iterate the tree once and put the
nodes into an array. This allows me to check for the presence of
various objects quickly, for the purposes of this discussion two
objects are deemed to be equal if a pointer comparison is true.
Essentially what I'm looking for is the quickest way to determine
if any of the objects stored in another array, are no longer
present in the content array, that is the array derived from the
content tree.
As far as I can see there are two NSArray methods of interest -
containsObject: and -indexOfObjectIdenticalTo:, the documentation
states that -containsObject: uses the NSObject protocol method -
isEqual: to determine equality. However the docs are vague as to
what the default implementation does stating instead that the
implementation depends on the context.
As all I need is a simple pointer comparison -
indexOfObjectIdenticalTo: seemed like a better option, however my
tests indicated that the -containsObject: method was slightly faster!?
The tree I am iterating contains under 50 objects (it will, or
rather might have to, contain many more - at which point speed will
be essential, this really depends on the user so it isn't just
premature optimisation on my part). Perhaps my results are not too
indicative.
I was just curious as to whether someone else had any insight into
which was a faster/more efficient way of accomplishing this?
- Keith
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
40frontiernet.net
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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