@@ -0,0 +1,2351 @@
+/*%0A * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one%0A * or more contributor license agreements. Licensed under the Elastic License%0A * 2.0 and the Server Side Public License, v 1; you may not use this file except%0A * in compliance with, at your election, the Elastic License 2.0 or the Server%0A * Side Public License, v 1.%0A */%0Apackage org.elasticsearch.common.bytes;%0A%0Aimport org.elasticsearch.common.io.stream.BytesStreamOutput;%0Aimport org.elasticsearch.common.io.stream.StreamInput;%0Aimport org.elasticsearch.common.unit.ByteSizeUnit;%0Aimport org.elasticsearch.common.unit.ByteSizeValue;%0Aimport org.openjdk.jmh.annotations.Benchmark;%0Aimport org.openjdk.jmh.annotations.BenchmarkMode;%0Aimport org.openjdk.jmh.annotations.Fork;%0Aimport org.openjdk.jmh.annotations.Measurement;%0Aimport org.openjdk.jmh.annotations.Mode;%0Aimport org.openjdk.jmh.annotations.OutputTimeUnit;%0Aimport org.openjdk.jmh.annotations.Param;%0Aimport org.openjdk.jmh.annotations.Scope;%0Aimport org.openjdk.jmh.annotations.Setup;%0Aimport org.openjdk.jmh.annotations.State;%0Aimport org.openjdk.jmh.annotations.Warmup;%0A%0Aimport java.io.IOException;%0Aimport java.util.concurrent.TimeUnit;%0A%0A@Warmup(iterations = 5)%0A@Measurement(iterations = 7)%0A@BenchmarkMode(Mode.AverageTime)%0A@OutputTimeUnit(TimeUnit.MILLISECONDS)%0A@State(Scope.Thread)%0A@Fork(value = 1)%0Apublic class PagedBytesReferenceBenchmark %7B%0A%0A    @Param(value = %7B %221%22 %7D)%0A    private int dataMb;%0A%0A    private BytesReference pagedBytes;%0A%0A    @Setup%0A    public void initResults() throws IOException %7B%0A        final BytesStreamOutput tmp = new BytesStreamOutput();%0A        final long bytes = new ByteSizeValue(dataMb, ByteSizeUnit.MB).getBytes();%0A        for (int i = 0; i %3C bytes / 8; i++) %7B%0A            tmp.writeLong(i);%0A        %7D%0A        pagedBytes = tmp.bytes();%0A        if (pagedBytes instanceof PagedBytesReference == false) %7B%0A            throw new AssertionError(%22expected paged PagedBytesReference but saw %5B%22 + pagedBytes.getClass() + %22%5D%22);%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    public long readLong() throws IOException %7B%0A        long res = 0L;%0A        final int reads = pagedBytes.length() / 8;%0A        try (StreamInput streamInput = pagedBytes.streamInput()) %7B%0A            for (int i = 0; i %3C reads; i++) %7B%0A                res = res %5E streamInput.readLong();%0A            %7D%0A        %7D%0A        return res;%0A    %7D%0A%7D%0A

Add Benchmark for Long Reads from BytesReference Stream (#71310)