I had a hint on jmh setup, moreover, it was about HashMap . As already noted, you measure a lot more than just HashMap::get here. But even in this case, I doubted that java-9 would be much slower, so I measured myself (the last jmh is built from sources, java-8 and 9).
I did not change my code - I just added more heaps (10 GB) and even more workouts, thereby reducing the "error" that you see after ±
Using java-8:
Benchmark Mode Cnt Score Error Units SOExample.bmHashMap avgt 25 22.059 ± 0.276 ns/op
Using java-9:
Benchmark Mode Cnt Score Error Units SOExample.bmHashMap avgt 25 23.954 ± 0.383 ns/op
The results look at the level with almost no noticeable difference (it's still nano-seconds), as you can see. Also, if you really want to test only HashMap::get , than your methods could just return a call to this, for example:
@Benchmark @Fork(5) public int bmHashMap(SOExample.Data data) { return data.hashmap.get(data.key);
source share