For profiling yourself, there are many options. One free profiler I've used and which I would recommend is EQATEC. There are plenty more to choose from, many of which are referenced in this SO question.
As for implementations, the first few that pop into mind are Dictionary<TKey, TValue>
, SortedDictionary<TKey, TValue>
and SortedList<TKey, TValue>
. Of course, I would be inclined to guess that Dictionary<TKey, TValue>
is the fastest since it's the simplest in terms of features. But I haven't ever tested them against one another for speed.
Note that the above classes are all generic, which should make them more efficient than HashTable
in at least one sense: they do not require boxing/unboxing of keys and values as System.Object
, which results in unnecessary memory allocation.
Something else to be aware of is that since you're in a multithreaded scenario, you'll need to take care to lock your reads/writes somehow. (The above classes, unlike HashTable
, are not guaranteed to be thread-safe for multiple readers and a writer.) Locking on a common object may be your best bet in most cases, whereas if you're performing more reads than writes you might want to consider using a ReaderWriterLock
or ReaderWriterLockSlim
(both of which permit switching between multiple simultaneous readers and a single writer). If you are enumerating over the collection then you should really be locking anyway--even with a HashTable
.