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.

Candidates

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

Source

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

Conclusions

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.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s