NSSet Inefficiency
NSSet Inefficiency
- Subject: NSSet Inefficiency
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sat, 23 Mar 2002 15:11:44 +0100
I have an app which creates about 2 million objects, halve of these are
different. And I want to keep only these different objects.
1. strategy: NSMutableSet
set = [ NSMutableSet initWithCapacity: 0]
for( ii = 1 to 2000000)
create newThing[ii]
oldThing = [ set member: newThing ]
if ( oldThing == nil )
[ set addObject: newThing ]
else
[ newThing release ]
use oldThing
This seemed somehow slow, so I tried:
2. strategy: SortedArray
I added a Category to MutableArray with insertObject: usingSelector:
set = [ NSMutableArray initWithCapacity: 0]
for( ii = 1 to 2000000)
create newThing[ii]
oldThing = [ set insertObject: newThing usingSelector: some method ]
if ( oldThing == nil )
// newThing was really new and has been inserted
else
[ newThing release ]
use oldThing
This turned out to be 10 times faster than the first strategy: 2 minutes
instead of 20.
Now two questions:
1. Is NSSet really that inefficient, of did I commit any grave mistakes?
2. Is there any efficient open-source implementation of a sorted array
(maybe using B-trees) around?
Gerriet
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.