Home / Class/ ByteBufZeroingBenchmark Class — netty Architecture

ByteBufZeroingBenchmark Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  c05369af_119c_c7eb_6d00_b6edefca7975["ByteBufZeroingBenchmark"]
  e36e2898_e7e8_0b8e_aea9_9b8c639b2d8f["ByteBufZeroingBenchmark.java"]
  c05369af_119c_c7eb_6d00_b6edefca7975 -->|defined in| e36e2898_e7e8_0b8e_aea9_9b8c639b2d8f
  d2a15544_ca8e_59b2_ef30_c44bf27824dd["setup()"]
  c05369af_119c_c7eb_6d00_b6edefca7975 -->|method| d2a15544_ca8e_59b2_ef30_c44bf27824dd
  e14995c5_97bd_a118_bbcd_9e23bfc3efa7["ByteBuf()"]
  c05369af_119c_c7eb_6d00_b6edefca7975 -->|method| e14995c5_97bd_a118_bbcd_9e23bfc3efa7
  2e8cb9bc_cd5b_8c93_996f_03d74a3174c8["teardown()"]
  c05369af_119c_c7eb_6d00_b6edefca7975 -->|method| 2e8cb9bc_cd5b_8c93_996f_03d74a3174c8

Relationship Graph

Source Code

microbench/src/main/java/io/netty/buffer/ByteBufZeroingBenchmark.java lines 33–125

@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 10, time = 400, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, time = 200, timeUnit = TimeUnit.MILLISECONDS)
public class ByteBufZeroingBenchmark extends AbstractMicrobenchmark {

    @Param({
            "1",
            "2",
            "3",
            "4",
            "7",
            "8",
            "15",
            "64",
            "65",
            "1024",
    })
    private int bytes = 1024;
    @Param({
            "true",
            "false",
    })
    private boolean direct;
    @Param({
            "true",
            "false",
    })
    private boolean pooled;
    @Param({
            "false",
    })
    public String checkAccessible;

    @Param({
            "false",
    })
    public String checkBounds;
    @Param({
            "0",
            "1",
    })
    public int startOffset;
    private ByteBuf buffer;
    private int offset;

    @Setup
    public void setup() {
        System.setProperty("io.netty.buffer.checkAccessible", checkAccessible);
        System.setProperty("io.netty.buffer.checkBounds", checkBounds);
        ByteBufAllocator allocator = pooled? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT;
        int capacityRequired = startOffset + bytes;
        offset = 0;
        buffer = direct? alignedDirectAllocation(allocator, capacityRequired, 8) :
                allocator.heapBuffer(capacityRequired, capacityRequired);
        if (startOffset > 0) {
            offset += startOffset;
        }
    }

    private ByteBuf alignedDirectAllocation(ByteBufAllocator allocator, int bytes, final int alignment) {
        ByteBuf buffer = allocator.directBuffer(bytes + alignment, bytes + alignment);
        final long address = buffer.memoryAddress();
        final int remainder = (int) address % alignment;
        final int nextAlignedOffset = alignment - remainder;
        this.offset = nextAlignedOffset;
        return buffer;
    }

    @Benchmark
    public ByteBuf setZero() {
        final ByteBuf buffer = this.buffer;
        buffer.setZero(offset, bytes);
        return buffer;
    }

    @Benchmark
    public ByteBuf setBytes() {
        final ByteBuf buffer = this.buffer;
        final int offset = this.offset;

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free