HashTable vs Dictionary Performance

HashTable vs Dictionary Performance

  • Comments 1

Last week I needed to implement a little complex data structure for our last project. I needed to keep keys in a hashtable like structure for fast access but I also needed a queue structure to remove LRU item since the size in the memory is limited. For the hashtable I used c# hashtable which takes any object as the key and I implemented this. Since the value can be any object I need to do casting when I retrieved objects from hashtable. We had a code review with my lead and he asked why I chose hashtable  versus dictionary. A dictionary is more self explanatory since you need to specify types but a hashtable must have better performance, at least I assumed so but he was not sure about that.  Anyway when I had time I wrote a small app to test hashtable and dictionary performance in c#. I add 10k guids to both and search for a different set of 10k guids(so that I will have the worst case search result which is not exist). At the end What I found is dictionary has nearly %33 better performance over hashtable but if I change dictionary comparison to case insensitive it did its job in 3x times of hashtable. So if you don’t have case sensitivity issue, dictionary is a better alternative for string key types.

Leave a Comment
  • Please add 2 and 5 and type the answer here:
  • Post
  • Hi,

    Thanks for the information. Can you post the code or send me the code?

    That gives us to understand how did you come to a conclusion of this stats.

    Thanks for reading my request as well as sharing the information

    Regards,

    Chakravarthy

    dskcheck@msn.com

Page 1 of 1 (1 items)