[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Using NS[Int]Number for dictionary keys
From: |
Mark Dalrymple |
Subject: |
Using NS[Int]Number for dictionary keys |
Date: |
Tue, 30 Aug 2005 14:38:13 -0400 |
Greetings,
I'm working with some folks that are wanting to put a large number of
objects into a dictionary, keyed by number. When using string keys
created with
string1 = [NSString stringWithFormat:@"%d", clauseNumber];
[clauseHashTable setObject:currentClause forKey:string1];
with clauseNumber going from 1 to a bit over 1 million, It takes
about 6 seconds (2-way G5 running OS X) to populate a dictionary.
When using NSNumbers,
number = [NSNumber numberWithInt: clauseNumber];
[clauseHashTable setObject: currentClause
forKey: number];
It takes about 21 minutes. Using the same code with Apple's Cocoa
libraries takes about 3 seconds.
Using the 'sample' utility over a span of about 2 minutes (sampling 3
miliseconds), I get:
40313 -[GSMutableDictionary setObject:forKey:]
14758 objc_msg_lookup
14758 objc_msg_lookup
12556 _GLOBAL__I_Cyrillic_conv_base
12556 _GLOBAL__I_Cyrillic_conv_base
12060 -[NSNumber isEqual:]
9524 -[NSNumber isEqualToNumber:]
7295 -[NSIntNumber compare:]
2206 GSNumberInfoFromObject
That Cyrillic_conv_base thing is a bit odd, and there's a lot of time
eaten in NSNumber isEqual and friends. Using NSIntNumber rather than
NSNumber gave similar results.
So my question is, is NSNumber not suited to being used for
dictionary keys in GNUstep, or could it be a problem with the
hashing / equality functions?
Thank you for your time,
++Mark Dalrymple, markd@borkware.com
http://borkware.com
- Using NS[Int]Number for dictionary keys,
Mark Dalrymple <=