On Wed, 7 Jun 2000, Jochen F. Rick wrote:
[snip]
> > - "Pages are OrderedCollection: pages was a dictionary of in-sequence
> > numbers pointing at pages. Changing that to a collection is more
> > elegant." How so? Dictionaries are much faster for finding
> > individual elements, no?
>
> I sure hope not. (AnOrderedCollection at: int) is faster than (ADictionary
> at: int). Not much faster, but about 40% faster.
A very lame benchmarking:
| test results |
results _ Array new: 3.
test _ Dictionary
newFrom: {1->'one'. 2->'two'. 3->'three'. 4->'four'. 5->'five'}.
results at: 1 put: (Time millisecondsToRun: [10000 timesRepeat: [test
at: 2]]).
test _ IdentityDictionary
newFrom: {1->'one'. 2->'two'. 3->'three'. 4->'four'. 5->'five'}.
results at: 2 put: (Time millisecondsToRun: [10000 timesRepeat: [test
at: 2]]).
test _ OrderedCollection newFrom: #('one' 'two' 'three' 'four' 'five').
results at: 3 put: (Time millisecondsToRun: [10000 timesRepeat: [test
at: 2]]).
results.
This yields: (224 232 64 )
So, OrderedCollections are an order of magnitude faster (which I
expected), but IdentityDictionarys are consistently slower than
Dictionarys, which surprised me. I wonder if that's because of using
SmallIntegers for the keys.
Replacing the second test with:
test _ IdentityDictionary
newFrom: {'1'->'one'. '2'->'two'. '3'->'three'. 4->'four'. '5'->'five'}.
results at: 2 put: (Time millisecondsToRun: [10000 timesRepeat: [test
at: '2']]).
Yields: (230 241 48 )
So using strings (if unique) gives you little loss over SmallIntegers.
Stringfying the first test in the same way gies:
(309 234 55 )
So, IdentityDictionarys start to win. Vs. Dictionaries, not
OrderedCollections. I imagine they'd win bigger as the keys got more
complex and = got faster than ==.
Cheers,
Bijan.