3 ms·
When microbenchmarking Java it is a good idea to use a framework to make sure you get an accurate result despite the compiler trying to eliminate your code. In
by arielweisberg 13y ago
When microbenchmarking Java it is a good idea to use a framework to make sure you get an accurate result despite the compiler trying to eliminate your code. In their case it looks like they are getting real numbers since Java and C are the same order of magnitude, but blog posts like this are where people learn benchmark hygiene.
I recommend JMH which I believe is what was developed @ Oracle to handle this task.
I used it to microbenchmark various Java maps for small map sizes and showed some of the results. https://groups.google.com/forum/#!topic/mechanical-sympathy/dxbTH30_ok0 https://groups.google.com/forum/#!topic/mechanical-sympathy/...
I also found the discussion of various map implementation tradeoffs and caveats useful. That Google group is a great resource.
One thing you have to keep in mind when benchmarking maps is locality and cache affinity and how things will work outside the benchmark when things don't fit in cache or have been evicted by your application.
In my case map lookups showed up in profiles relating to various lookup tables that define logic and policy. There can be a surprising number spread out as well as some hit hard in tight loops.