Home / Class/ CompositeByteBufRandomAccessBenchmark Class — netty Architecture

CompositeByteBufRandomAccessBenchmark Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  7a6f8511_08a9_b32f_b547_c6fd0a21a1c7["CompositeByteBufRandomAccessBenchmark"]
  1305feb2_2c86_a330_a59b_379df40deca3["CompositeByteBufRandomAccessBenchmark.java"]
  7a6f8511_08a9_b32f_b547_c6fd0a21a1c7 -->|defined in| 1305feb2_2c86_a330_a59b_379df40deca3
  e6ec10bb_8bea_4f9e_64f5_dd31c192cc80["setup()"]
  7a6f8511_08a9_b32f_b547_c6fd0a21a1c7 -->|method| e6ec10bb_8bea_4f9e_64f5_dd31c192cc80
  936a4804_809f_c09e_1945_ddd669471734["teardown()"]
  7a6f8511_08a9_b32f_b547_c6fd0a21a1c7 -->|method| 936a4804_809f_c09e_1945_ddd669471734
  c0443b5f_ccb7_8877_ee61_7aca0bbfa7bf["setGetLong()"]
  7a6f8511_08a9_b32f_b547_c6fd0a21a1c7 -->|method| c0443b5f_ccb7_8877_ee61_7aca0bbfa7bf
  ca513eff_5f20_f735_d138_b3cc96c58834["ByteBuf()"]
  7a6f8511_08a9_b32f_b547_c6fd0a21a1c7 -->|method| ca513eff_5f20_f735_d138_b3cc96c58834

Relationship Graph

Source Code

microbench/src/main/java/io/netty/buffer/CompositeByteBufRandomAccessBenchmark.java lines 35–122

@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
public class CompositeByteBufRandomAccessBenchmark extends AbstractMicrobenchmark {

    public enum ByteBufType {
        SMALL_CHUNKS {
            @Override
            ByteBuf newBuffer(int length) {
                return newBufferSmallChunks(length);
            }
        },
        LARGE_CHUNKS {
            @Override
            ByteBuf newBuffer(int length) {
                return newBufferLargeChunks(length);
            }
        };
        abstract ByteBuf newBuffer(int length);
    }

    @Param({
            "64",
            "10240",
            "1024000",
    }) // ({ "64", "1024", "10240", "102400", "1024000" })
    public int size;

    @Param
    public ByteBufType bufferType;

    private ByteBuf buffer;
    private Random random;

    @Setup
    public void setup() {
        buffer = bufferType.newBuffer(size);
        random = new Random(0L);
    }

    @TearDown
    public void teardown() {
        buffer.release();
    }

    @Benchmark
    public long setGetLong() {
        int i = random.nextInt(size - 8);
        return buffer.setLong(i, 1).getLong(i);
    }

    @Benchmark
    public ByteBuf setLong() {
        int i = random.nextInt(size - 8);
        return buffer.setLong(i, 1);
    }

    private static ByteBuf newBufferSmallChunks(int length) {

        List<ByteBuf> buffers = new ArrayList<ByteBuf>(((length + 1) / 45) * 19);
        for (int i = 0; i < length + 45; i += 45) {
            for (int j = 1; j <= 9; j++) {
                buffers.add(EMPTY_BUFFER);
                buffers.add(wrappedBuffer(new byte[j]));
            }
            buffers.add(EMPTY_BUFFER);
        }

        ByteBuf buffer = wrappedBuffer(Integer.MAX_VALUE, buffers.toArray(new ByteBuf[0]));

        // Truncate to the requested capacity.
        return buffer.capacity(length).writerIndex(0);
    }

    private static ByteBuf newBufferLargeChunks(int length) {

        List<ByteBuf> buffers = new ArrayList<ByteBuf>((length + 1) / 512);
        for (int i = 0; i < length + 1536; i += 1536) {
            buffers.add(wrappedBuffer(new byte[512]));
            buffers.add(EMPTY_BUFFER);
            buffers.add(wrappedBuffer(new byte[1024]));
        }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free