New unit tests 12 times slower under Gradle (solved)

John Neffenger john at status6.com
Tue Feb 12 19:25:34 UTC 2019


I figured it out. It's the old version of JUnit that we're using.

Although we're building OpenJFX with Gradle 4.8, which bundles JUnit 
4.12, our "build.gradle" file specifies the older JUnit 4.8.2 (which is 
downloaded, along with Hamcrest 1.1, into the Gradle cache under 
"~/.gradle/caches").

And JUnit 4.8.2 is more than 57 times slower than JUnit 4.12 when 
comparing primitive arrays!

The change that makes it so much faster is the call to 
"Arrays.deepEquals", not found in the older version:

public abstract class ComparisonCriteria {
     public void arrayEquals(String message,
             Object expecteds, Object actuals)
             throws ArrayComparisonFailure {
         if (expecteds == actuals
             || Arrays.deepEquals(
                 new Object[] {expecteds}, new Object[] {actuals})) {
             // The reflection-based loop below is potentially very slow,
             // especially for primitive arrays. The deepEquals check
             // allows us to circumvent it in the usual case where the
             // arrays are exactly equal.
             return;
         }
         ...
     }
     ...
}

Mystery solved! Can we upgrade to JUnit 4.12 (and Hamcrest 1.3) in the 
build?

John


More information about the openjfx-dev mailing list