dcsimg
Speed of retrieving objects from Hastable
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   roger_tong
Posted On:   Tuesday, May 22, 2001 07:44 PM

Supposing to put many objects into a hastable, is there a much difference beween using short characters as a key and long character as a key? In other words, is it much faster using sessionMap.get("fgsagsfdgfgfdgfgffdf") than using sessionMap.get("fg")?

Re: Speed of retrieving objects from Hastable

Posted By:   John_Zukowski  
Posted On:   Thursday, May 24, 2001 04:30 PM

Starting with 1.3, hash codes are cached. Given they they need to be calculted to put something into the Hashtable, there is no speed difference on retrieval of long vs. short keys. Prior to 1.3, they weren't cached and there would be a difference.


As another person mentioned, assuming you don't need the thready safety, HashMap is quicker as it is unsynchronized.

Re: Speed of retrieving objects from Hastable

Posted By:   Michael_Wax  
Posted On:   Tuesday, May 22, 2001 08:13 PM

The speed of the Java hashing algorithm for strings should be roughly proportional to the string length, so shorter keys will buy you some speed. However, I would guess that a small fraction of the processing time is spent on the hashing algorithm in a typical case. If you need speed, you could probably gain more by switching from a synchronized Hashtable to an unsynchronized HashMap, given the relatively long time that the synchronization process takes.
About | Sitemap | Contact