Search

03 October, 2008

Dictionary VS Hash Table

We all know how useful a hash table can be, but if you are using the .NET Framework 2.0 you should be using a Dictionary instead. A dictionary and a hash table in .NET 2.0 are very similar but with 1 main difference, a dictionary is faster because it does not need to box and unbox the data as a hash table would.

I made a simple program to see just how much faster a dictionary is than a hash table. I ran the test 20 times for each data set and the results were close each time. A GUID as the key and a boolean as the data.

This is the results of the last test for each dataset.

Time in Milliseconds for 100,000 keysDictionaryHash Table
Inserting34.4126476.0970
Reading18.900531.1648
Deleting21.247430.4655

 

Time in Seconds for 10,000,000 keysDictionaryHash Table
Inserting6.570414326.9096540
Reading3.13628915.6670613
Deleting3.46233164.8830676

 

No comments:

Post a Comment