Which is faster HashTable or HashMap
Hi,
I am trying to compare time required to add data , delete data etc. on both HashTable and HashMap. The experiment shows me that HashTable is faster than HashMap. which is contradictory to what we have learned earlier. So if anybody knows the reason why I am getting such kind of result please tell me.
I suspect your benchmark is flawed - are you factoring in gc? are you using sequential keys?
Hashtable is performant with sequential keys but use "random" keys and you will find, as expected, HashMap is faster.
Realistically this is a micro-optimization that I doubt you will ever need to worry about. Pick the most suitable implementation for your needs.
YoGeea at 2007-7-11 23:46:35 >

> I am trying to compare time required to add data ,
> delete data etc. on both HashTable and HashMap. The
> experiment shows me that HashTable is faster than
> HashMap. which is contradictory to what we have
> learned earlier. So if anybody knows the reason why
> I am getting such kind of result please tell me.
Use a HashMap. It has a more stable performance when loaded with "skewed" data sets.
The performance difference between maps are determined largely by the actual load factor. The default load factor of both maps is 0.75 but if the maps have different growt strategies they may end up with a different actual load factor for the same number of inserted elements. And this will influence the performance.
So use the HashMap for it's stability and increase the performance by decreasing the default load factor to say 0.5.
YoGeea at 2007-7-11 23:46:35 >
