FROM : glenn andreas
DATE : Thu Dec 23 21:33:53 2004
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_removed>
<http://www.gandreas.com/> oh my!
Mad, Bad, and Dangerous to Know
DATE : Thu Dec 23 21:33:53 2004
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_removed>
<http://www.gandreas.com/> oh my!
Mad, Bad, and Dangerous to Know
| Related mails | Author | Date |
|---|---|---|
| Aurélien Hugelé | Dec 23, 14:21 | |
| M. Uli Kusterer | Dec 23, 15:00 | |
| glenn andreas | Dec 23, 15:58 | |
| Aurélien Hugelé | Dec 23, 19:17 | |
| glenn andreas | Dec 23, 21:33 |






Cocoa mail archive

