Home / Class/ AppendableCharSequenceBenchmark Class — netty Architecture

AppendableCharSequenceBenchmark Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  a2f3b91a_9f96_cb74_48f7_69352371a5b0["AppendableCharSequenceBenchmark"]
  ae8bba5c_44ff_08d7_a1e9_b7b6683bb2b8["AppendableCharSequenceBenchmark.java"]
  a2f3b91a_9f96_cb74_48f7_69352371a5b0 -->|defined in| ae8bba5c_44ff_08d7_a1e9_b7b6683bb2b8
  6496a72f_b9f4_c150_c698_dcdd215e4119["setup()"]
  a2f3b91a_9f96_cb74_48f7_69352371a5b0 -->|method| 6496a72f_b9f4_c150_c698_dcdd215e4119
  bd8fc4fd_968b_4548_5e93_b559925bd826["appendCheckBeforeCopy()"]
  a2f3b91a_9f96_cb74_48f7_69352371a5b0 -->|method| bd8fc4fd_968b_4548_5e93_b559925bd826
  9b423d87_ba24_dd04_87b0_9b3de906b5d0["appendCatchExceptionAfter()"]
  a2f3b91a_9f96_cb74_48f7_69352371a5b0 -->|method| 9b423d87_ba24_dd04_87b0_9b3de906b5d0
  849927dd_3af4_a929_39a1_87103e3c3526["checkReset()"]
  a2f3b91a_9f96_cb74_48f7_69352371a5b0 -->|method| 849927dd_3af4_a929_39a1_87103e3c3526
  3e478c86_6ed0_8712_9805_c9b9733d3636["expand()"]
  a2f3b91a_9f96_cb74_48f7_69352371a5b0 -->|method| 3e478c86_6ed0_8712_9805_c9b9733d3636

Relationship Graph

Source Code

microbench/src/main/java/io/netty/microbenchmark/common/AppendableCharSequenceBenchmark.java lines 29–87

@Threads(1)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
public class AppendableCharSequenceBenchmark extends AbstractMicrobenchmark {
    @Param({ "32", "64", "128", "256" })
    private int charsInitSize;

    @Param({ "10", "100", "10000", "1000000" })
    private int simulatedDataSize;

    private static final Random rand = new Random();
    private char[] chars;
    private char simulatedData;
    private int pos;

    @Setup(Level.Trial)
    public void setup() {
        chars = new char[charsInitSize];
        simulatedData = (char) rand.nextInt();
    }

    @Benchmark
    public void appendCheckBeforeCopy() {
        checkReset();
        if (pos == chars.length) {
            expand();
        }
        chars[pos++] = simulatedData;
    }

    @Benchmark
    public void appendCatchExceptionAfter() {
        checkReset();
        try {
            chars[pos++] = simulatedData;
        } catch (IndexOutOfBoundsException e) {
            expand();
            chars[pos - 1] = simulatedData;
        }
    }

    private void checkReset() {
        if (pos == simulatedDataSize) {
            pos = 0;
            chars = new char[charsInitSize];
        }
    }

    private void expand() {
        char[] old = chars;
        // double it
        int len = old.length << 1;
        if (len < 0) {
            throw new IllegalStateException();
        }
        chars = new char[len];
        System.arraycopy(old, 0, chars, 0, old.length);
    }
}

Frequently Asked Questions

What is the AppendableCharSequenceBenchmark class?
AppendableCharSequenceBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbenchmark/common/AppendableCharSequenceBenchmark.java.
Where is AppendableCharSequenceBenchmark defined?
AppendableCharSequenceBenchmark is defined in microbench/src/main/java/io/netty/microbenchmark/common/AppendableCharSequenceBenchmark.java at line 29.

Analyze Your Own Codebase

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

Try Supermodel Free