Low GC in Java: Using primitives
Overview
In a recent article I examined how using primitives and collections which support primitives natively instead of Wrappers and standard collections can reduce memory usage and improve performance.Different way to have a Map of int/Integer
There are a number of ways you can use int/Integer and a number of collections you store them in. Depending on which approach you use can have a big difference on the performance and the amount of garbage produced.Test | Performance Range | Memory used |
---|---|---|
Use Integer wrappers and HashMap | 71 - 134 (ns) | 53 MB/sec |
Use int primitives and HashMap | 45 - 76 (ns) | 36 MB/sec |
Use int primitives and FastMap | 58 - 93 (ns) | 28 MB/sec |
Use int primitives and TIntIntHashMap | 18 - 28 (ns) | nonimal |
Use int primitives and simple hash map | 6 - 9 (ns) | nonimal |
These tests were run on my new system.
Hi!
ReplyDeleteI found your article very interesting.
What do you mean by "Use int primitives and simple hash map", did you implemented your own Hash Map functions?
@akoskm, Yes, the simple HashMap implements just what is required for the test. Its code in in the "Directory of performance examples" link, or you can click SimpleHashMap
ReplyDelete