• 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
Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?


  • Subject: Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?
  • From: AurĂ©lien HugelĂ© <email@hidden>
  • Date: Thu, 23 Dec 2004 14:21:52 +0100

hi list !

i'm tuning my application and since a long time ago, i noticed that using indexOfObjectIdenticalTo: is far (i mean something like 1000 x faster on 20 000 items) faster that indexOfObject:

IMO indexOfObject is just Olog(n) because it needs full traversal of the array if the searched object is the last one.
but indexOfObjectIdenticalTo: use probably the same algorithm except that the equality test is faster (address equality instead of (slower?) isEqual: message)


but i think the speed difference would not be so large. I suppose that in fact, NSArray use an internal structure to link an object address to its index in the array...
Am i totally wrong ? is it "normal" that a "==" test is 1000 times faster than isEqual: ?


in Apple documentation, they show that isEqual: should be implemented like this :

-(void)isEqual:(id)anObject {
	if(anObject == self)
		return YES;

	if( ![anObject isKindOfClass:[self class])
		return NO;

return [self isEqualTo_PLACE_HERE_YOUR_OBJECT_:anObject]; // specialized isEqual, depends of the object internals, logic etc...
}


if all cocoa is implemented like that the difference between isEqual: and " == " should be quite minor (messaging overhead only)

what's your opinion ?

thanks

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?
      • From: glenn andreas <email@hidden>
    • Re: Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?
      • From: "M. Uli Kusterer" <email@hidden>
  • Prev by Date: Using atos -p to get symbolic name of address?
  • Next by Date: Re: Finder vs. Quartz performance.
  • Previous by thread: Re: Using atos -p to get symbolic name of address?
  • Next by thread: Re: Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?
  • Index(es):
    • Date
    • Thread