Strange speed dependency; help needed for benchmark, please

Ulf Zibis Ulf.Zibis at gmx.de
Wed Feb 4 11:50:44 PST 2009


Hi,

I experience very much different mutually contradictory times running my 
UTF-8 benchmark 
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/test/sun/nio/cs/UTF_8Benchmark.java?diff_format=s&rev=620&view=markup
for only 1 code unit pattern _against_ running for all code unit patterns:

selected pattern 4
time for sun.nio.cs.UTF_8_60$Decoder: 2851 ms
time for sun.nio.cs.UTF_8_70$Decoder: 2501 ms
time for sun.nio.cs.UTF_8_last$Decoder: 2310 ms
time for sun.nio.cs.UTF_8_new$Decoder: 2048 ms

selected all patterns (SRC_BUF = -1)
time for sun.nio.cs.UTF_8_60$Decoder: 4951 4925 5351 4531 5269 4686 ms
time for sun.nio.cs.UTF_8_70$Decoder: 476 3066 4815 3921 4907 3369 ms
time for sun.nio.cs.UTF_8_last$Decoder: 560 3237 4539 4575 4772 3334 ms
time for sun.nio.cs.UTF_8_new$Decoder: 531 3642 4741 4462 5497 3742 ms

The absolute difference can be explained very simply:
I am running the tests on a mobile machine (notebook), so during heavy 
test, CPU is getting hot, and is down-clocked automatically by power 
management.

... but I don't have any explanation for the relative differences 
(compare "pattern 4"-run against 2nd last column from "all patterns"-run).
In the 1st run UTF_8_new$Decoder is much faster than recent JDK7 
UTF_8_70$Decoder: 2048 ms ./. 2501 ms, but not in 2nd run: 5497 ms ./. 
4907 ms.

Also I experience significant differences, when I change the 
chronological order of the tested decoders, see line 29... :
        int dec = 0; // change process order of decoders for different 
results:
        decoders[dec++] = new UTF_8_60().newDecoder();
        decoders[dec++] = new UTF_8_70().newDecoder();
        decoders[dec++] = new UTF_8_last().newDecoder();
        decoders[dec++] = new UTF_8_new().newDecoder();


.... So can anybody please run my benchmark on a stable-clock machine 
and check also for different process order of decoders.
If I'm not wrong, you only need to download: UTF_8_60, UTF_8_70, 
UTF_8_last, UTF_8_new and UTF_8Benchmark from:
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/test/sun/nio/cs/?diff_format=s&rev=620#dirlist

Very much thanks for your help,

-Ulf



Am 02.02.2009 23:35, Ulf Zibis schrieb:
> Hi all,
>
> I have experienced a strange speed dependency of HotSpot compiled code 
> after little change in code, which is not part of the "hot" loop.
> Is there any explanation for this behavior?
>
> Code before little change:
>
> class UTF_8_new extends Unicode {
>
>        // ....
>
>        private static CoderResult malformed(ByteBuffer src, int sp,
>                                             CharBuffer dst, int dp, 
> int nb) {
>            src.position(sp -= nb - src.arrayOffset());
>            CoderResult cr = malformedN(src, nb);
>            updatePositions(src, sp, dst, dp);
>            return cr;
>        }
>
>        // ....
>
>            while (sp < sl) {
>                // ....
>                    int b2 = sa[sp++];
>                    int b3 = sa[sp++];
>                    int b4 = sa[sp++];
>                    if (isMalformed4(b1, b2))
>                        return malformed(src, sp-2, dst, dp, 2);
>                    if (isNotContinuation(b3))
>                        return malformed(src, sp-1, dst, dp, 3);
>                    if (isNotContinuation(b4))
>                        return malformed(src, sp, dst, dp, 4);
>                    if (dp >= dl - 1)
>                        return overflow(src, sp-4, dst, dp);
>                    int uc = (b1 << 18) ^ (b2 << 12) ^ (b3 << 06) ^ b4 
> ^ 0x00381f80;
>                // ....
>            }
>
> The above code has following output (note gain against UTF_8_70$Decoder):
> time for sun.nio.cs.UTF_8_60$Decoder: 2701 ms
> time for sun.nio.cs.UTF_8_70$Decoder: 1984 ms
> time for sun.nio.cs.UTF_8_new$Decoder: 1720 ms  // gain: 264 ms
> time for sun.nio.cs.UTF_8_last$Decoder: 2110 ms
>
>
> Following small code change made the "hot" part of the loop much slower:
>
> class UTF_8_new extends Unicode {
>
>        // ....
>
>        private static CoderResult malformed(ByteBuffer src, int sp,
>                                             CharBuffer dst, int dp, 
> int nb) {
>            src.position(sp - src.arrayOffset());    // removed 
> subtraction of nb
>            CoderResult cr = malformedN(src, nb);
>            updatePositions(src, sp, dst, dp);
>            return cr;
>        }
>
>        // ....
>
>            while (sp < sl) {
>                // ....
>                    int b2 = sa[sp++];
>                    int b3 = sa[sp++];
>                    int b4 = sa[sp++];
>                    if (isMalformed4(b1, b2))
>                        return malformed(src, sp-4, dst, dp, 2);
>                    if (isNotContinuation(b3))
>                        return malformed(src, sp-4, dst, dp, 3);
>                    if (isNotContinuation(b4))
>                        return malformed(src, sp-4, dst, dp, 4);
>                    if (dp >= dl - 1)
>                        return overflow(src, sp-4, dst, dp);
>                    int uc = (b1 << 18) ^ (b2 << 12) ^ (b3 << 06) ^ b4 
> ^ 0x00381f80;
>                // ....
>            }
>
> time for sun.nio.cs.UTF_8_60$Decoder: 2731 ms
> time for sun.nio.cs.UTF_8_70$Decoder: 1981 ms
> time for sun.nio.cs.UTF_8_new$Decoder: 1872 ms  // gain: 109 ms
> time for sun.nio.cs.UTF_8_last$Decoder: 2094 ms
>
> For complete sources compare following revisions (... and run 
> UTF_8Benchmark.java ):
> https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/test/sun/nio/cs/?diff_format=s&rev=613 
>
> https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/test/sun/nio/cs/?diff_format=s&rev=614 
>
>
>
> -Ulf
>
>
>
>




More information about the hotspot-compiler-dev mailing list