Home / Class/ SnappyDirectBenchmark Class — netty Architecture

SnappyDirectBenchmark Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  7ad1569d_0704_7b12_e97c_432fbce0c6c9["SnappyDirectBenchmark"]
  98a302fa_94d0_d92a_c78c_4b4b364ab65d["SnappyDirectBenchmark.java"]
  7ad1569d_0704_7b12_e97c_432fbce0c6c9 -->|defined in| 98a302fa_94d0_d92a_c78c_4b4b364ab65d
  57eafa5d_01b9_5baf_dae0_263a7cd65561["setup()"]
  7ad1569d_0704_7b12_e97c_432fbce0c6c9 -->|method| 57eafa5d_01b9_5baf_dae0_263a7cd65561
  cf642669_36f3_5d41_760f_2c3610ed9a71["ByteBuf()"]
  7ad1569d_0704_7b12_e97c_432fbce0c6c9 -->|method| cf642669_36f3_5d41_760f_2c3610ed9a71
  04723d27_4aa7_f532_e2b3_fdbe2b02683a["teardown()"]
  7ad1569d_0704_7b12_e97c_432fbce0c6c9 -->|method| 04723d27_4aa7_f532_e2b3_fdbe2b02683a

Relationship Graph

Source Code

microbench/src/main/java/io/netty/microbench/snappy/SnappyDirectBenchmark.java lines 41–108

@State(Scope.Benchmark)
@Fork(1)
@Threads(1)
@Warmup(iterations = 5)
@Measurement(iterations = 3)
public class SnappyDirectBenchmark extends AbstractMicrobenchmark {

    @Param({ "true", "false" })
    public boolean reuseHashTable;
    private ByteBuf buffer;
    private Snappy snappy;
    private ByteBuf in;
    private ByteBuf out;

    @Param({ "4096", "2048", "1024", "512", "256", "128" })
    private int bufferSizeInBytes;

    @AuxCounters(value = Type.OPERATIONS)
    @State(Scope.Thread)
    public static class AllocationMetrics {
        private long inputSize;

        private long outputSize;

        public long compressedRatio() {
            return inputSize / outputSize;
        }
    }

    @Setup
    public void setup() throws UnsupportedEncodingException {
        ByteBufAllocator allocator = UnpooledByteBufAllocator.DEFAULT;
        buffer = allocator.buffer(bufferSizeInBytes);

        if (reuseHashTable) {
            snappy = Snappy.withHashTableReuse();
        } else {
            snappy = new Snappy();
        }

        byte[] compressibleByteArray = new byte[buffer.writableBytes()];
        Arrays.fill(compressibleByteArray, (byte) 1);
        buffer.writeBytes(compressibleByteArray);

        in = Unpooled.wrappedBuffer(compressibleByteArray);
        out = Unpooled.directBuffer();
    }

    @Benchmark
    public ByteBuf encode(AllocationMetrics allocationMetrics) {
        int length = in.readableBytes();
        snappy.encode(in, out, length);
        in.resetReaderIndex();
        allocationMetrics.inputSize += length;
        allocationMetrics.outputSize += out.readableBytes();
        out.setIndex(0, 0);

        return out;
    }

    @TearDown(Level.Trial)
    public void teardown() {
        buffer.release();
        buffer = null;
        out.release();
        out = null;
    }
}

Frequently Asked Questions

What is the SnappyDirectBenchmark class?
SnappyDirectBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbench/snappy/SnappyDirectBenchmark.java.
Where is SnappyDirectBenchmark defined?
SnappyDirectBenchmark is defined in microbench/src/main/java/io/netty/microbench/snappy/SnappyDirectBenchmark.java at line 41.

Analyze Your Own Codebase

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

Try Supermodel Free