RFR: CODETOOLS-7902829: JMH Statistics implementations do not follow Comparable spec [v3]

Vladimir Sitnikov github.com+213894+vlsi at openjdk.java.net
Thu Feb 18 13:18:07 UTC 2021


On Thu, 18 Feb 2021 12:53:03 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> `Comparable.compareTo` spec says: "Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object."
>> 
>> Unfortunately, that is not followed by JMH Statistics, because they get the order wrong. The tests that are supposed to catch this are also wrong.
>
> Aleksey Shipilev has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Use Double.compare instead

jmh-core/src/test/java/org/openjdk/jmh/util/TestListStatistics.java line 190:

> 188:         for (double conf : new double[] {0.5, 0.9, 0.99, 0.999, 0.9999, 0.99999}) {
> 189:             Assert.assertTrue("Diff significant at " + conf, s1.isDifferent(s2, conf));
> 190:             Assert.assertEquals(-1, s1.compareTo(s2, conf));

Technically speaking, the assert should be `less than 0` rather than `equal to -1`.
`-2` is a valid result of `compareTo` call.

WDYT?

-------------

PR: https://git.openjdk.java.net/jmh/pull/21


More information about the jmh-dev mailing list