Home / Class/ Utf8EncodingBenchmark Class — netty Architecture

Utf8EncodingBenchmark Class — netty Architecture

Architecture documentation for the Utf8EncodingBenchmark class in Utf8EncodingBenchmark.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  14a7a416_5aef_2dc8_262c_52585d9f0cac["Utf8EncodingBenchmark"]
  2b24fd8e_0929_c5f9_e723_89adc6666e12["Utf8EncodingBenchmark.java"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|defined in| 2b24fd8e_0929_c5f9_e723_89adc6666e12
  9737e0a7_b59c_526f_e54f_aa40c2d6f750["init()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| 9737e0a7_b59c_526f_e54f_aa40c2d6f750
  8672ad76_2f39_d763_6d37_66647a40d806["closeStream()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| 8672ad76_2f39_d763_6d37_66647a40d806
  8579a28e_9c41_bc87_3e6e_8002eda6c0bf["closeReader()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| 8579a28e_9c41_bc87_3e6e_8002eda6c0bf
  ef8024d7_360c_986d_649b_122b08f70bb2["nestedByteBufUtilWriteUtf8String()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| ef8024d7_360c_986d_649b_122b08f70bb2
  f67c465f_16d7_b461_3fea_829318fab5ac["nestedByteBufUtilWriteUtf8String1()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| f67c465f_16d7_b461_3fea_829318fab5ac
  9a397e18_92c4_387e_71f2_9583055a5fde["nestedByteBufUtilWriteUtf8String2()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| 9a397e18_92c4_387e_71f2_9583055a5fde
  513827ff_bed4_7b54_e28a_b48376d3c6a9["nestedByteBufUtilWriteUtf8String3()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| 513827ff_bed4_7b54_e28a_b48376d3c6a9
  f1f7edb9_19b3_7cb7_08af_07cdcc4524fe["nestedByteBufUtilWriteUtf8String4()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| f1f7edb9_19b3_7cb7_08af_07cdcc4524fe
  c6f14c07_25c2_66b0_94e8_bb079b72d2bc["nestedByteBufUtilWriteUtf8String5()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| c6f14c07_25c2_66b0_94e8_bb079b72d2bc
  1c29c1cc_08c3_5f23_d00c_acb93563b9c5["nestedByteBufUtilWriteUtf8String6()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| 1c29c1cc_08c3_5f23_d00c_acb93563b9c5
  d8aa92f0_ae06_23d8_f85c_be011632b34e["byteBufUtilWriteUtf8String()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| d8aa92f0_ae06_23d8_f85c_be011632b34e
  4a1b455a_1ec2_36c3_95d0_354210621249["byteBufUtilWriteUtf8Bimorphic()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| 4a1b455a_1ec2_36c3_95d0_354210621249
  e31c037b_eba8_bd82_50a7_87f835c67237["byteBufUtilWriteUtf8Megamorphic()"]
  14a7a416_5aef_2dc8_262c_52585d9f0cac -->|method| e31c037b_eba8_bd82_50a7_87f835c67237

Relationship Graph

Source Code

microbench/src/main/java/io/netty/microbench/buffer/Utf8EncodingBenchmark.java lines 39–278

@Fork(value = 2, jvmArgsAppend = "-XX:MaxInlineLevel=9")
public class Utf8EncodingBenchmark extends AbstractMicrobenchmark {
    private static class AnotherCharSequence implements CharSequence {
        private final char[] chars;

        AnotherCharSequence(String chars) {
            this.chars = new char[chars.length()];
            chars.getChars(0, chars.length(), this.chars, 0);
        }

        @Override
        public int length() {
            return chars.length;
        }

        @Override
        public char charAt(int i) {
            return chars[i];
        }

        @Override
        public CharSequence subSequence(int start, int end) {
            throw new UnsupportedOperationException();
        }

        @Override
        public String toString() {
            throw new UnsupportedOperationException();
        }
    }

    // experiment test input
    private String[] strings;
    private StringBuilder[] stringBuilders;
    private AnotherCharSequence[] anotherCharSequences;
    private AsciiString[] asciiStrings;

    @Param({
            "true",
            "false",
    })
    private boolean direct;
    private ByteBuf buffer;

    @Param({
            "true",
            "false",
    })
    private boolean noUnsafe;
    private int dataSetLength;

    @Setup
    public void init() {
        System.setProperty("io.netty.noUnsafe", Boolean.valueOf(noUnsafe).toString());
        int maxExpectedSize = 0;
        List<String> strings = new ArrayList<String>();
        List<StringBuilder> stringBuilders = new ArrayList<StringBuilder>();
        List<AnotherCharSequence> anotherCharSequenceList = new ArrayList<AnotherCharSequence>();
        List<AsciiString> asciiStrings = new ArrayList<AsciiString>();
        try (InputStream testTextStream = getClass().getResourceAsStream("/Utf8Samples.txt");
             InputStreamReader inStreamReader = new InputStreamReader(testTextStream, "UTF-8");
             BufferedReader buffReader = new BufferedReader(inStreamReader);) {

            String line;
            while ((line = buffReader.readLine()) != null) {
                strings.add(line);
                stringBuilders.add(new StringBuilder(line));
                anotherCharSequenceList.add(new AnotherCharSequence(line));
                asciiStrings.add(new AsciiString(line));
                maxExpectedSize = Math.max(maxExpectedSize, ByteBufUtil.utf8MaxBytes(line.length()));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        buffer = direct? Unpooled.directBuffer(maxExpectedSize, maxExpectedSize) :
                Unpooled.buffer(maxExpectedSize, maxExpectedSize);
        buffer.setByte(maxExpectedSize - 1, 0);
        this.strings = strings.toArray(new String[strings.size()]);
        this.stringBuilders = stringBuilders.toArray(new StringBuilder[stringBuilders.size()]);
        this.anotherCharSequences =
                anotherCharSequenceList.toArray(new AnotherCharSequence[anotherCharSequenceList.size()]);

Frequently Asked Questions

What is the Utf8EncodingBenchmark class?
Utf8EncodingBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbench/buffer/Utf8EncodingBenchmark.java.
Where is Utf8EncodingBenchmark defined?
Utf8EncodingBenchmark is defined in microbench/src/main/java/io/netty/microbench/buffer/Utf8EncodingBenchmark.java at line 39.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free