Explain why my two benchmarks are performing differently than I expect?

Aleksey Shipilev shade at redhat.com
Mon Oct 1 20:11:27 UTC 2018


On 10/01/2018 08:42 PM, David Karr wrote:
> I recently noticed some code in the codebase I work that looks like this
> (not with a hardcoded value):
> 
>         DecimalFormat df = new DecimalFormat("##0.00");
>         new BigDecimal(df.format(47.0));
> 
> I was pretty sure that was an inefficient way to do this, which I thought
> should be more like:
> 
>         new BigDecimal(47.0).setScale(2, BigDecimal.ROUND_HALF_UP);

...

> I'd appreciate any help understanding why this is behaving oppositely of
> what I would expect.

I think you need to start from JMH Samples:
  http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/

Notably JMHSample_08_DeadCode and JMHSample_35_Profilers.

-Aleksey




More information about the jmh-dev mailing list