Benchmarking hash table implementations – Java

Java implementations

It was pointed out that some Java hash table implementations were supposed to be faster than the native HashMap. This test was run enabling the Java process access to all 8 virtual cores, which was not the case in the previous benchmarks.


  • Java native HashMap – Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
  • Java Colt – v1.0.2
  • Java Trove – v3.0.3


The inner loop was modified as below (or similar)

long t1 = System.nanoTime();
for (int i = 0; i < r; i ++) {
  Integer x = m.get(b[i]);
  if (x != null)
    sum += x;
long t2 = System.nanoTime();

Results (Random integer lookups with a hit probability of 50%)

Benchmark Java


At least in this specific micro benchmark, the current native HashMap implementation seems to have improved and surpassed Trove and Colt for small hash sizes, and perform equally for larger.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s