Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Size of an entry in a Map

DZone's Guide to

Size of an entry in a Map

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

There have been some very good articles on the size of a map. However as a map grows, it initial size become less important and the size per entry is what matters.

How are the sizes measured

In these tests an int key and long values are used. This adds a small but realistic size to each entry.

Size per entry of a medium sized Map

The following are the size per entry in bytes. The Map has 1024 entries.

Type of Map 32-bit 64-bit compressed 64-bit not compressed
TIntLongHashMap 26.9 26.9 27.0
FastMap (recycled) 32.0 39.9 47.9
IdentityHashMap 48.0 56.0 80.0
ConcurrentSkipListMap 68.3 76.1 108.3
TreeMap 64.0 80.0 112.0
HashMap 64.0 80.0 112.0
SynchronizedMap 64.0 80.0 112.0
ConcurrentHashMap 65.2 81.4 114.0
Properties 68.0 84.0 120.0
Hashtable 68.0 84.0 120.0
LinkedHashMap 72.0 88.0 128.1
WeakHashMap 80.0 88.0 136.1
 
The Javolution FastMap needed to be recycled. If it is not recycled, it was the largest per entry.

Conclusion

It may be worth considering The GNU Trove collections if you have primitive keys and/or values. However if you have non-trivial keys or values classes, the size of the collection is less likely to matter.

The Code

SizeOfMapsTest.java

 

From http://vanillajava.blogspot.com/2011/07/size-of-entry-in-map.html

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}