Re: NSSet Inefficiency
Re: NSSet Inefficiency
- Subject: Re: NSSet Inefficiency
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sun, 24 Mar 2002 21:03:26 +0100
On Sonntag, Mdrz 24, 2002, at 03:23 , Ondra Cada wrote:
On Saturday, March 23, 2002, at 03:11 , Gerriet M. Denkmann wrote:
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]
Can't work at all. You wanted [[NSMutableSet alloc] init] (or
initWithCapacity:2000000, the zero's nonsense)
Actually it works with zero. It works better for higher numbers; it
works best for an initial capacity of about 3,000,000 (even higher
values do not give better speed). The speed increases about 4fold
between initial capacity of 0 to 3,000,000 .
Obviously NSMutableSet is very sensitive to a sensible initial capacity.
On the other hand, the initial capacity seems to have no measurable
influence on MSMutableArray.
for( ii = 1 to 2000000)
create newThing[ii]
This is C++, can't work in ObjC. Even in ObjC++ you can't (AFAIK) mix
the C++ pseuod-object things with real ObjC ones.
This is not C++, this is just pseudo-code which should explain the
strategy I tried.
I am sorry to have confused you; I thought it was obvious that this was
not real code.
Probably I should have stated this explicitly.
oldThing = [ set member: newThing ]
if ( oldThing == nil )
[ set addObject: newThing ]
else
[ newThing release ]
use oldThing
This pseudo code (can't be real one, compiler would never swallow this)
Correct.
first of all, what you shown use here could not be even compiled, not
even worked. Therefore I can't be sure why it did not work, but I
*GUESS* that the problem is that you haven't implemented -hash properly
for objects which you store in an NSSet.
Well, each object to be stored has an array of 10 bytes.
As hash I used (in pseudo-code) first_four_bytes ^ next_four_bytes ^
last_two_bytes.
This was the best I could think of.
1. Is NSSet really that inefficient, of did I commit any grave
mistakes?
It is as efficient as a nicely implemented hash table can ever be. As
such though it heavily depends on the quality of the hash, though.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.