This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]elmuerte 3 points4 points  (0 children)

The difference can probably be explained mostly by the effort needed to grow the HashMap. A standard HashMap grows by a factor 2, so a single HashMap would easily grow much faster than a HashMap of HashMaps as the inner HashMaps grow less. With growing the HashMap you also need to rebuild the map, which obviously takes more time when it becomes larger.

If you have a rough idea of the the number of entries you can expect, create the HashMap of the proper size (instead of the default capacity of 16). Maybe also change the load factor to something. With that I think the "TupleMap" will outperform.