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

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


  • Subject: Re: Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?
  • From: glenn andreas <email@hidden>
  • Date: Thu, 23 Dec 2004 14:33:53 -0600


On Dec 23, 2004, at 12:17 PM, Aurélien Hugelé wrote:

for those of you that are interested :

here is my test code : compiled with gcc3.3 -03


RESULTS :

// CASE 1 : "slow" indexOfObject:

# Report 0 - Session 1 - Time Profile of Essais
SharkProfileViewer
# Generated from the visible portion of the outline view
+ 13.9 s _dyld_start (dyld)
| + 13.9 s _start (Essais)
| | + 13.9 s main (Essais)
| | | + 13.9 s -[NSCFArray indexOfObject:] (Foundation)
| | | | + 13.9 s CFArrayGetFirstIndexOfValue (CoreFoundation)
| | | | | + 9.7 s CFEqual (CoreFoundation)
| | | | | 298.2 ms __CF_INVOKE_CALLBACK (CoreFoundation)


So this means that of the 13.9 seconds spent in indexOfObject:, 9.7 are in CFEqual and another .298 in CF_INVOKE_CALLBACK. That's a total of about 4 seconds left for the rest of indexOfObject (including fetching all the elements).

// CASE 2 : "fast" indexOfObjectIdenticalTo:
# Report 0 - Session 2 - Time Profile of Essais
SharkProfileViewer
# Generated from the visible portion of the outline view
+ 3.5 s _dyld_start (dyld)
| + 3.5 s _start (Essais)
| | + 3.5 s main (Essais)
| | | + 3.4 s -[NSCFArray indexOfObjectIdenticalTo:] (Foundation)

Here we see that indexOfObjectIdenticalTo: is 3.4 seconds (and no CFEqual calls, etc... are needed)



almost 5 times faster !


But that extra time is spent in CFEqual which does far more than a simple ==.


imo the algorithm is clearly different :

| | | + 3.4 s -[NSCFArray indexOfObjectIdenticalTo:] (Foundation)
| | | | 1.3 s CFArrayGetValueAtIndex (CoreFoundation) => it seems the index is IMMEDIATLY found ??


It still take (3.4 - 1.3) = 2.1 seconds to iterate through and do == so it's not "immediately found".


whereas :

| | | + 13.9 s -[NSCFArray indexOfObject:] (Foundation)
| | | | + 13.9 s CFArrayGetFirstIndexOfValue (CoreFoundation) => the index must be found by enumerating the array...



It still pretty much comes down to iterating through all the objects in the array and doing "==" vs sending "isEqualTo:".

Write your own versions that do this and time them - the results should be similar.




Glenn Andreas                      email@hidden 
<http://www.gandreas.com/> oh my!
Mad, Bad, and Dangerous to Know
 _______________________________________________
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

References: 
 >Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ? (From: Aurélien Hugelé <email@hidden>)
 >Re: Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ? (From: glenn andreas <email@hidden>)
 >Re: Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ? (From: Aurélien Hugelé <email@hidden>)

  • Prev by Date: Re: NSFilePromisePboardType
  • Next by Date: Re: Trouble with mouseMoved and custom views
  • Previous by thread: Re: Why is indexOfObjectIdenticalTo: *far* faster than indexOfObject: ?
  • Next by thread: [OT] [ANN] Alternative object serialization format
  • Index(es):
    • Date
    • Thread