Hi Stuart,

On 5/14/15 3:44 AM, Stuart Marks wrote:
Hi all,

Please review this change to optimize a test. Basically the test did string formatting for every assertion, but the string was thrown away if the assertion passed -- the most common case. The change is to do the string formatting only when an assertion fails and information needs to be printed out.

Thanks to Andrey Zakharov for discovering and investigating this.

Bug report:

    https://bugs.openjdk.java.net/browse/JDK-8078463

Webrev:

    http://cr.openjdk.java.net/~smarks/reviews/8078463/webrev.0/

On my (new, fast) laptop, with JVM options -Xcomp -XX:+DeoptimizeALot -client, the unmodified test takes about 21.4 seconds to run. The modified test takes only 12.3 seconds.

Note that I have added several overloads of check() with different arguments. I tried an alternative, which is a varargs version of check():

    static void    check(boolean cond, String fmt,    Object... args) {
        if (cond) {
            pass();
        } else {
            fail(String.format(fmt, args));
        }
    }

This of course is much simpler code, but it took 14.2 seconds, about 15% slower than the proposed version. Is the simpler code worth the slowdown? I could go either way.
I'm curious: have you tried with using a lambda instead? changing:

 394     static void check(String desc, boolean cond) {
 395         if (cond) {
 396             pass();
 397         } else {
 398             fail(desc);
 399         }
 400     }

into

static void check(Supplier<String> descSupplier, boolean cond) {
    if (cond) {
        pass();
    } else {
        fail(descSupplier.get())
    }
}

I wonder how the performance would compare...

best regards,

-- daniel

Thanks.

s'marks



Reply via email to