8282047: Enhance StringDecode/Encode microbenchmarks

Reviewed-by: bchristi
This commit is contained in:
Claes Redestad 2022-03-01 10:20:22 +00:00
parent 22b93a31c9
commit d4d12ad1d9
2 changed files with 291 additions and 144 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,17 +22,7 @@
*/ */
package org.openjdk.bench.java.lang; package org.openjdk.bench.java.lang;
import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole; import org.openjdk.jmh.infra.Blackhole;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -40,28 +30,30 @@ import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime) @BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS) @OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(value = 3) @Fork(value = 2)
@Warmup(iterations = 5, time = 2) @Warmup(iterations = 5, time = 3)
@Measurement(iterations = 5, time = 3) @Measurement(iterations = 5, time = 3)
@State(Scope.Thread) @State(Scope.Thread)
public class StringDecode { public class StringDecode {
@Param({"US-ASCII", "ISO-8859-1", "UTF-8", "MS932", "ISO-8859-6", "ISO-2022-KR"}) // Reduced by default to only UTF-8, previous coverage:
// @Param({"US-ASCII", "ISO-8859-1", "UTF-8", "MS932", "ISO-8859-6", "ISO-2022-KR"})
@Param({"UTF-8"})
private String charsetName; private String charsetName;
private Charset charset; private Charset charset;
private byte[] asciiString; private byte[] asciiString;
private byte[] longAsciiString;
private byte[] utf16String; private byte[] utf16String;
private byte[] longUtf16String; private byte[] longUtf16EndString;
private byte[] longUtf16StartString; private byte[] longUtf16StartString;
private byte[] longLatin1String; private byte[] longUtf16OnlyString;
private byte[] latin1String;
private byte[] longLatin1EndString;
private byte[] longLatin1StartString;
private byte[] longLatin1OnlyString;
@Setup private static final String LOREM = """
public void setup() {
charset = Charset.forName(charsetName);
asciiString = "ascii string".getBytes(charset);
utf16String = "UTF-\uFF11\uFF16 string".getBytes(charset);
longUtf16String = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ac sem eu Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ac sem eu
urna egestas placerat. Etiam finibus ipsum nulla, non mattis dolor cursus a. urna egestas placerat. Etiam finibus ipsum nulla, non mattis dolor cursus a.
Nulla nec nisl consectetur, lacinia neque id, accumsan ante. Curabitur et Nulla nec nisl consectetur, lacinia neque id, accumsan ante. Curabitur et
@ -70,90 +62,145 @@ public class StringDecode {
per conubia nostra, per inceptos himenaeos. Suspendisse erat diam, fringilla per conubia nostra, per inceptos himenaeos. Suspendisse erat diam, fringilla
sed massa sed, posuere viverra orci. Suspendisse tempor libero non gravida sed massa sed, posuere viverra orci. Suspendisse tempor libero non gravida
efficitur. Vivamus lacinia risus non orci viverra, at consectetur odio laoreet. efficitur. Vivamus lacinia risus non orci viverra, at consectetur odio laoreet.
Suspendisse potenti. Suspendisse potenti.""";
private static final String UTF16_STRING = "\uFF11".repeat(31);
private static final String LATIN1_STRING = "\u00B6".repeat(31);
Phasellus vel nisi iaculis, accumsan quam sed, bibendum eros. Sed venenatis @Setup
nulla tortor, et eleifend urna sodales id. Nullam tempus ac metus sit amet public void setup() {
sollicitudin. Nam sed ex diam. Praesent vitae eros et neque condimentum charset = Charset.forName(charsetName);
consectetur eget non tortor. Praesent bibendum vel felis nec dignissim. asciiString = LOREM.substring(0, 32).getBytes(charset);
Maecenas a enim diam. Suspendisse quis ligula at nisi accumsan lacinia id longAsciiString = LOREM.repeat(200).getBytes(charset);
hendrerit sapien. \uFF11Donec aliquam mattis lectus eu ultrices. Duis eu nisl\uFF11 utf16String = "UTF-\uFF11\uFF16 string".getBytes(charset);
euismod, blandit mauris vel, \uFF11placerat urna. Etiam malesuada enim purus, longUtf16EndString = LOREM.repeat(4).concat(UTF16_STRING).getBytes(charset);
tristique mollis odio blandit quis.\uFF11 Vivamus posuere. \uFF11 longUtf16StartString = UTF16_STRING.concat(LOREM.repeat(4)).getBytes(charset);
\uFF11 longUtf16OnlyString = UTF16_STRING.repeat(10).getBytes(charset);
""".getBytes(charset); latin1String = LATIN1_STRING.getBytes(charset);
longUtf16StartString = """ longLatin1EndString = LOREM.repeat(4).concat(LATIN1_STRING).getBytes(charset);
\uFF11 longLatin1StartString = LATIN1_STRING.concat(LOREM.repeat(4)).getBytes(charset);
Lorem ipsum dolor sit amet, \uFF11consectetur adipiscing elit. Aliquam ac sem eu longLatin1OnlyString = LATIN1_STRING.repeat(10).getBytes(charset);
urna egestas \uFF11placerat. Etiam finibus ipsum nulla, non mattis dolor cursus a.
Nulla \uFF11nec nisl consectetur, lacinia neque id, accumsan ante. Curabitur et
sapien in \uFF11magna porta ultricies. \uFF11Sed vel pellentesque nibh. Pellentesque dictum
dignissim diam eu ultricies. Class aptent taciti sociosqu ad litora torquent
per conubia nostra, per inceptos himenaeos. Suspendisse erat diam, fringilla
sed massa sed, posuere viverra orci. Suspendisse tempor libero non gravida
efficitur. Vivamus lacinia risus non orci viverra, at consectetur odio laoreet.
Suspendisse potenti.
Phasellus vel nisi iaculis, accumsan quam sed, bibendum eros. Sed venenatis
nulla tortor, et eleifend urna sodales id. Nullam tempus ac metus sit amet
sollicitudin. Nam sed ex diam. Praesent vitae eros et neque condimentum
consectetur eget non tortor. Praesent bibendum vel felis nec dignissim.
Maecenas a enim diam. Suspendisse quis ligula at nisi accumsan lacinia id
hendrerit sapien. Donec aliquam mattis lectus eu ultrices. Duis eu nisl
euismod, blandit mauris vel, placerat urna. Etiam malesuada enim purus,
tristique mollis odio blandit quis. Vivamus posuere.
""".getBytes(charset);
longLatin1String = """
a\u00B6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6
b\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6
c\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6
d\u00F6\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6
e\u00F6\u00F6\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6
f\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6
g\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6
h\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6
i\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6
j\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6\u00F6\u00F6
k\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6\u00F6
l\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6\u00F6
m\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00F6\u00B6\u00F6\u00F6
""".getBytes(charset);
} }
@Benchmark @Benchmark
public String decodeAsciiCharsetName() throws Exception { @CompilerControl(CompilerControl.Mode.DONT_INLINE)
return new String(asciiString, charsetName); public void decodeAsciiShort(Blackhole bh) throws Exception {
bh.consume(new String(asciiString, charset));
bh.consume(new String(longAsciiString, 0, 15, charset));
bh.consume(new String(asciiString, 0, 3, charset));
bh.consume(new String(longAsciiString, 512, 512 + 7, charset));
} }
@Benchmark @Benchmark
public String decodeAscii() throws Exception { @CompilerControl(CompilerControl.Mode.DONT_INLINE)
return new String(asciiString, charset); public void decodeAsciiLong(Blackhole bh) throws Exception {
bh.consume(new String(longAsciiString, charset));
bh.consume(new String(longAsciiString, 0, 1024 + 31, charset));
} }
@Benchmark @Benchmark
public String decodeLatin1Long() throws Exception { @CompilerControl(CompilerControl.Mode.DONT_INLINE)
return new String(longLatin1String, charset); public void decodeLatin1Short(Blackhole bh) throws Exception {
bh.consume(new String(latin1String, charset));
bh.consume(new String(latin1String, 0, 15, charset));
bh.consume(new String(latin1String, 0, 3, charset));
bh.consume(new String(longLatin1OnlyString, 512, 512 + 7, charset));
} }
@Benchmark @Benchmark
public String decodeUTF16Short() throws Exception { @CompilerControl(CompilerControl.Mode.DONT_INLINE)
return new String(utf16String, charset); public String decodeLatin1LongStart() throws Exception {
return new String(longLatin1StartString, charset);
} }
@Benchmark @Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public String decodeLatin1LongEnd() throws Exception {
return new String(longLatin1EndString, charset);
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public String decodeLatin1LongOnly() throws Exception {
return new String(longLatin1OnlyString, charset);
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void decodeLatin1Mixed(Blackhole bh) throws Exception {
bh.consume(new String(longLatin1EndString, charset));
bh.consume(new String(longLatin1StartString, charset));
bh.consume(new String(latin1String, charset));
bh.consume(new String(longLatin1OnlyString, charset));
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void decodeUTF16Short(Blackhole bh) throws Exception {
bh.consume(new String(utf16String, charset));
bh.consume(new String(utf16String, 0, 15, charset));
bh.consume(new String(utf16String, 0, 3, charset));
bh.consume(new String(utf16String, 0, 7, charset));
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public String decodeUTF16LongEnd() throws Exception { public String decodeUTF16LongEnd() throws Exception {
return new String(longUtf16String, charset); return new String(longUtf16EndString, charset);
} }
@Benchmark @Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public String decodeUTF16LongStart() throws Exception { public String decodeUTF16LongStart() throws Exception {
return new String(longUtf16StartString, charset); return new String(longUtf16StartString, charset);
} }
@Benchmark @Benchmark
public void decodeUTF16LongMixed(Blackhole bh) throws Exception { @CompilerControl(CompilerControl.Mode.DONT_INLINE)
public String decodeUTF16LongOnly() throws Exception {
return new String(longUtf16OnlyString, charset);
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void decodeUTF16Mixed(Blackhole bh) throws Exception {
bh.consume(new String(longUtf16StartString, charset)); bh.consume(new String(longUtf16StartString, charset));
bh.consume(new String(longUtf16String, charset)); bh.consume(new String(longUtf16EndString, charset));
bh.consume(new String(utf16String, charset));
bh.consume(new String(longUtf16OnlyString, charset));
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void decodeAllMixed(Blackhole bh) throws Exception {
bh.consume(new String(utf16String, charset));
bh.consume(new String(longUtf16EndString, charset));
bh.consume(new String(utf16String, 0, 15, charset));
bh.consume(new String(longUtf16StartString, charset));
bh.consume(new String(asciiString, 0, 3, charset));
bh.consume(new String(longUtf16OnlyString, charset));
bh.consume(new String(latin1String, charset));
bh.consume(new String(longLatin1EndString, charset));
bh.consume(new String(longLatin1StartString, charset));
bh.consume(new String(latin1String, 0, 7, charset));
bh.consume(new String(longLatin1OnlyString, charset));
bh.consume(new String(asciiString, charset));
bh.consume(new String(longAsciiString, charset));
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void decodeShortMixed(Blackhole bh) throws Exception {
bh.consume(new String(utf16String, 0, 15, charset));
bh.consume(new String(latin1String, 0, 15, charset));
bh.consume(new String(asciiString, charset));
bh.consume(new String(utf16String, charset));
bh.consume(new String(latin1String, 0, 3, charset));
bh.consume(new String(asciiString, 0, 3, charset));
bh.consume(new String(utf16String, 0, 7, charset));
bh.consume(new String(latin1String, charset));
bh.consume(new String(asciiString, 0, 7, charset));
bh.consume(new String(utf16String, 0, 3, charset));
bh.consume(new String(latin1String, 0, 7, charset));
bh.consume(new String(asciiString, 0, 15, charset));
} }
} }

View File

@ -30,97 +30,197 @@ import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime) @BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS) @OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(value = 3) @Fork(value = 2)
@Warmup(iterations = 5, time = 2) @Warmup(iterations = 5, time = 3)
@Measurement(iterations = 5, time = 3) @Measurement(iterations = 5, time = 3)
@State(Scope.Thread) @State(Scope.Thread)
public class StringEncode { public class StringEncode {
@Param({"US-ASCII", "ISO-8859-1", "UTF-8", "MS932", "ISO-8859-6"}) // Reduced by default to only UTF-8, previous coverage:
// @Param({"US-ASCII", "ISO-8859-1", "UTF-8", "MS932", "ISO-8859-6", "ISO-2022-KR"})
@Param({"UTF-8"})
private String charsetName; private String charsetName;
private Charset charset; private Charset charset;
private String asciiString; private String asciiString;
private String asciiString3;
private String asciiString7;
private String asciiString15;
private String longAsciiString;
private String longAsciiString1055;
private String utf16String; private String utf16String;
private String longUtf16String; private String utf16String3;
private String utf16String7;
private String utf16String15;
private String longUtf16EndString;
private String longUtf16StartString; private String longUtf16StartString;
private String longUtf16OnlyString;
private String latin1String;
private String latin1String3;
private String latin1String7;
private String latin1String15;
private String longLatin1EndString;
private String longLatin1StartString;
private String longLatin1OnlyString;
private static final String LOREM = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ac sem eu
urna egestas placerat. Etiam finibus ipsum nulla, non mattis dolor cursus a.
Nulla nec nisl consectetur, lacinia neque id, accumsan ante. Curabitur et
sapien in magna porta ultricies. Sed vel pellentesque nibh. Pellentesque dictum
dignissim diam eu ultricies. Class aptent taciti sociosqu ad litora torquent
per conubia nostra, per inceptos himenaeos. Suspendisse erat diam, fringilla
sed massa sed, posuere viverra orci. Suspendisse tempor libero non gravida
efficitur. Vivamus lacinia risus non orci viverra, at consectetur odio laoreet.
Suspendisse potenti.""";
private static final String UTF16_STRING = "\uFF11".repeat(31);
private static final String LATIN1_STRING = "\u00B6".repeat(31);
@Setup @Setup
public void setup() { public void setup() {
charset = Charset.forName(charsetName); charset = Charset.forName(charsetName);
asciiString = "ascii string"; asciiString = LOREM.substring(0, 32);
utf16String = "UTF-\uFF11\uFF16 string"; asciiString3 = LOREM.substring(0, 3);
longUtf16String = """ asciiString7 = LOREM.substring(0, 7);
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ac sem eu asciiString15 = LOREM.substring(0, 15);
urna egestas placerat. Etiam finibus ipsum nulla, non mattis dolor cursus a. longAsciiString = LOREM.repeat(200);
Nulla nec nisl consectetur, lacinia neque id, accumsan ante. Curabitur et longAsciiString1055 = longAsciiString.substring(0, 1055);
sapien in magna porta ultricies. Sed vel pellentesque nibh. Pellentesque dictum utf16String = UTF16_STRING;
dignissim diam eu ultricies. Class aptent taciti sociosqu ad litora torquent utf16String3 = UTF16_STRING.substring(0, 3);
per conubia nostra, per inceptos himenaeos. Suspendisse erat diam, fringilla utf16String7 = UTF16_STRING.substring(0, 7);
sed massa sed, posuere viverra orci. Suspendisse tempor libero non gravida utf16String15 = UTF16_STRING.substring(0, 15);
efficitur. Vivamus lacinia risus non orci viverra, at consectetur odio laoreet. longUtf16EndString = LOREM.repeat(4).concat(UTF16_STRING);
Suspendisse potenti. longUtf16StartString = UTF16_STRING.concat(LOREM.repeat(4));
longUtf16OnlyString = UTF16_STRING.repeat(10);
Phasellus vel nisi iaculis, accumsan quam sed, bibendum eros. Sed venenatis latin1String = LATIN1_STRING;
nulla tortor, et eleifend urna sodales id. Nullam tempus ac metus sit amet latin1String3 = LATIN1_STRING.substring(0, 3);
sollicitudin. Nam sed ex diam. Praesent vitae eros et neque condimentum latin1String7 = LATIN1_STRING.substring(0, 7);
consectetur eget non tortor. Praesent bibendum vel felis nec dignissim. latin1String15 = LATIN1_STRING.substring(0, 15);
Maecenas a enim diam. Suspendisse quis ligula at nisi accumsan lacinia id longLatin1EndString = LOREM.repeat(4).concat(LATIN1_STRING);
hendrerit sapien. Donec aliquam mattis lectus eu ultrices. Duis eu nisl longLatin1StartString = LATIN1_STRING.concat(LOREM.repeat(4));
euismod, blandit mauris vel, placerat urna. Etiam malesuada enim purus, longLatin1OnlyString = LATIN1_STRING.repeat(10);
tristique mollis odio blandit quis. Vivamus posuere.
\uFF11
""";
longUtf16StartString = """
\uFF11
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ac sem eu
urna egestas placerat. Etiam finibus ipsum nulla, non mattis dolor cursus a.
Nulla nec nisl consectetur, lacinia neque id, accumsan ante. Curabitur et
sapien in magna porta ultricies. Sed vel pellentesque nibh. Pellentesque dictum
dignissim diam eu ultricies. Class aptent taciti sociosqu ad litora torquent
per conubia nostra, per inceptos himenaeos. Suspendisse erat diam, fringilla
sed massa sed, posuere viverra orci. Suspendisse tempor libero non gravida
efficitur. Vivamus lacinia risus non orci viverra, at consectetur odio laoreet.
Suspendisse potenti.
Phasellus vel nisi iaculis, accumsan quam sed, bibendum eros. Sed venenatis
nulla tortor, et eleifend urna sodales id. Nullam tempus ac metus sit amet
sollicitudin. Nam sed ex diam. Praesent vitae eros et neque condimentum
consectetur eget non tortor. Praesent bibendum vel felis nec dignissim.
Maecenas a enim diam. Suspendisse quis ligula at nisi accumsan lacinia id
hendrerit sapien. Donec aliquam mattis lectus eu ultrices. Duis eu nisl
euismod, blandit mauris vel, placerat urna. Etiam malesuada enim purus,
tristique mollis odio blandit quis. Vivamus posuere.
""";
} }
@Benchmark @Benchmark
public byte[] encodeAsciiCharsetName() throws Exception { @CompilerControl(CompilerControl.Mode.DONT_INLINE)
return asciiString.getBytes(charset); public void encodeAsciiShort(Blackhole bh) throws Exception {
}
@Benchmark
public byte[] encodeAscii() throws Exception {
return asciiString.getBytes(charset);
}
@Benchmark
public void encodeMix(Blackhole bh) throws Exception {
bh.consume(asciiString.getBytes(charset)); bh.consume(asciiString.getBytes(charset));
bh.consume(asciiString3.getBytes(charset));
bh.consume(asciiString15.getBytes(charset));
bh.consume(asciiString7.getBytes(charset));
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void encodeAsciiLong(Blackhole bh) throws Exception {
bh.consume(longAsciiString.getBytes(charset));
bh.consume(longAsciiString1055.getBytes(charset));
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void encodeUTF16Short(Blackhole bh) throws Exception {
bh.consume(utf16String.getBytes(charset)); bh.consume(utf16String.getBytes(charset));
bh.consume(utf16String3.getBytes(charset));
bh.consume(utf16String15.getBytes(charset));
bh.consume(utf16String7.getBytes(charset));
} }
@Benchmark @Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public byte[] encodeUTF16LongEnd() throws Exception { public byte[] encodeUTF16LongEnd() throws Exception {
return longUtf16String.getBytes(charset); return longUtf16EndString.getBytes(charset);
} }
@Benchmark @Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public byte[] encodeUTF16LongStart() throws Exception { public byte[] encodeUTF16LongStart() throws Exception {
return longUtf16StartString.getBytes(charset); return longUtf16StartString.getBytes(charset);
} }
@Benchmark @Benchmark
public byte[] encodeUTF16() throws Exception { @CompilerControl(CompilerControl.Mode.DONT_INLINE)
return utf16String.getBytes(charset); public byte[] encodeUTF16LongOnly() throws Exception {
return longUtf16OnlyString.getBytes(charset);
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void encodeUTF16Mixed(Blackhole bh) throws Exception {
bh.consume(utf16String.getBytes(charset));
bh.consume(longUtf16StartString.getBytes(charset));
bh.consume(longUtf16EndString.getBytes(charset));
bh.consume(longUtf16OnlyString.getBytes(charset));
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void encodeLatin1Short(Blackhole bh) throws Exception {
bh.consume(latin1String.getBytes(charset));
bh.consume(latin1String3.getBytes(charset));
bh.consume(latin1String15.getBytes(charset));
bh.consume(latin1String7.getBytes(charset));
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public byte[] encodeLatin1LongOnly() throws Exception {
return longLatin1OnlyString.getBytes(charset);
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public byte[] encodeLatin1LongStart() throws Exception {
return longLatin1StartString.getBytes(charset);
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public byte[] encodeLatin1LongEnd() throws Exception {
return longLatin1EndString.getBytes(charset);
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void encodeLatin1Mixed(Blackhole bh) throws Exception {
bh.consume(longLatin1EndString.getBytes(charset));
bh.consume(longLatin1StartString.getBytes(charset));
bh.consume(longLatin1OnlyString.getBytes(charset));
bh.consume(latin1String.getBytes(charset));
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void encodeAllMixed(Blackhole bh) throws Exception {
bh.consume(utf16String.getBytes(charset));
bh.consume(longUtf16StartString.getBytes(charset));
bh.consume(asciiString7.getBytes(charset));
bh.consume(longUtf16EndString.getBytes(charset));
bh.consume(latin1String3.getBytes(charset));
bh.consume(longUtf16OnlyString.getBytes(charset));
bh.consume(longLatin1EndString.getBytes(charset));
bh.consume(longLatin1StartString.getBytes(charset));
bh.consume(utf16String15.getBytes(charset));
bh.consume(longLatin1OnlyString.getBytes(charset));
bh.consume(latin1String.getBytes(charset));
bh.consume(asciiString.getBytes(charset));
bh.consume(longAsciiString.getBytes(charset));
}
@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public void encodeShortMixed(Blackhole bh) throws Exception {
bh.consume(utf16String3.getBytes(charset));
bh.consume(latin1String7.getBytes(charset));
bh.consume(asciiString15.getBytes(charset));
bh.consume(utf16String.getBytes(charset));
bh.consume(latin1String3.getBytes(charset));
bh.consume(asciiString7.getBytes(charset));
bh.consume(utf16String15.getBytes(charset));
bh.consume(latin1String.getBytes(charset));
bh.consume(asciiString3.getBytes(charset));
bh.consume(utf16String7.getBytes(charset));
bh.consume(latin1String15.getBytes(charset));
bh.consume(asciiString.getBytes(charset));
} }
} }