• Post Reply Bookmark Topic Watch Topic
  • New Topic

Performance of HashMap in Java8  RSS feed

 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

We are trying out JMH to analyze performance of our application. To understand the utility better, we are trying to benchmark Hashmap initially. We are profiling a Hashmap get() call using JMH for Java 7 vs Java 8. 

Here is the code:


Here are the benchmark result for Java 7


Here are the benchmark result for Java 8

I am quite surprised with the results.  Java 8’s Hashmap get() is performing 2.5 times better than Java 7’s Hashmap get().  This is consistent above and below the TREEIFY_THRESHOLD.  Could you please let me know if this is expected?

Thanks
 
Stephan van Hulst
Saloon Keeper
Posts: 7992
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I took a look at the source for Java 7 and Java 8, and it appears HashMap was completely rewritten. Performance improvements are to be expected.
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:I took a look at the source for Java 7 and Java 8, and it appears HashMap was completely rewritten. Performance improvements are to be expected.


What I wanted to understand is that does this performance improvement correspond to the structural change to HashMap or does it reflect the overall improvement (GC optimization, Metaspace etc) in Java 8.

If I can get some insight into what is increasing the performance, that would be really helpful to me.
 
Stephan van Hulst
Saloon Keeper
Posts: 7992
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you download and compile the source for Java 7's HashMap, and then run a benchmark using it in a Java 8 environment.
 
Stephan van Hulst
Saloon Keeper
Posts: 7992
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might actually also want to do the same for the Java 8 version, so you can be sure they use the same compilation options.
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:You might actually also want to do the same for the Java 8 version, so you can be sure they use the same compilation options.

Thanks. I will check that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!