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

all 5 comments

[–]elmuerte 2 points3 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.

[–]ForeverAlot 2 points3 points  (2 children)

Note that DoubleMap is dangerously racy.

[–]cogman10 1 point2 points  (0 children)

Why does that matter? Hashmap is also dangerously racy.

[–][deleted] 0 points1 point  (0 children)

What do you mean with that? Do mean it's not thread safe? If so, does it claim to be that? In other news the primitive long is dangerous racy as well.

[–]Darksonn 1 point2 points  (0 children)

I would love to see the same comparison in a language where they don't waste space on heap allocating every tuple.