@@ -0,0 +1,2850 @@
+/*%0A * Copyright 2015 The Netty Project%0A *%0A * The Netty Project licenses this file to you under the Apache License,%0A * version 2.0 (the %22License%22); you may not use this file except in compliance%0A * with the License. You may obtain a copy of the License at:%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and limitations%0A * under the License.%0A */%0Apackage io.netty.microbench.buffer;%0A%0Aimport io.netty.buffer.ByteBuf;%0Aimport io.netty.buffer.ByteBufAllocator;%0Aimport io.netty.microbench.util.AbstractMicrobenchmark;%0Aimport org.openjdk.jmh.annotations.Benchmark;%0Aimport org.openjdk.jmh.annotations.Setup;%0Aimport org.openjdk.jmh.annotations.TearDown;%0A%0Aimport java.lang.reflect.Constructor;%0A%0Apublic class HeapByteBufBenchmark extends AbstractMicrobenchmark %7B%0A%0A    private ByteBuf unsafeBuffer;%0A    private ByteBuf buffer;%0A%0A    private static ByteBuf newBuffer(String classname) throws Exception %7B%0A        // Using reflection to workound package-private implementations.%0A        Class%3C?%3E clazz = Class.forName(classname);%0A        Constructor%3C?%3E constructor = clazz.getDeclaredConstructor(ByteBufAllocator.class, int.class, int.class);%0A        constructor.setAccessible(true);%0A        return (ByteBuf) constructor.newInstance(ByteBufAllocator.DEFAULT, 8, Integer.MAX_VALUE);%0A    %7D%0A%0A    @Setup%0A    public void setup() throws Exception %7B%0A        unsafeBuffer = newBuffer(%22io.netty.buffer.UnpooledUnsafeHeapByteBuf%22);%0A        buffer = newBuffer(%22io.netty.buffer.UnpooledHeapByteBuf%22);%0A        unsafeBuffer.writeLong(1L);%0A        buffer.writeLong(1L);%0A    %7D%0A%0A    @TearDown%0A    public void destroy() %7B%0A        unsafeBuffer.release();%0A        buffer.release();%0A    %7D%0A%0A    @Benchmark%0A    public byte getByteUnsafe() %7B%0A        return unsafeBuffer.getByte(0);%0A    %7D%0A%0A    @Benchmark%0A    public short getByte() %7B%0A        return buffer.getByte(0);%0A    %7D%0A%0A    @Benchmark%0A    public short getShortUnsafe() %7B%0A        return unsafeBuffer.getShort(0);%0A    %7D%0A%0A    @Benchmark%0A    public short getShort() %7B%0A        return buffer.getShort(0);%0A    %7D%0A%0A    @Benchmark%0A    public int getMediumUnsafe() %7B%0A        return unsafeBuffer.getMedium(0);%0A    %7D%0A%0A    @Benchmark%0A    public int getMedium() %7B%0A        return buffer.getMedium(0);%0A    %7D%0A%0A    @Benchmark%0A    public int getIntUnsafe() %7B%0A        return unsafeBuffer.getInt(0);%0A    %7D%0A%0A    @Benchmark%0A    public int getInt() %7B%0A        return buffer.getInt(0);%0A    %7D%0A%0A    @Benchmark%0A    public long getLongUnsafe() %7B%0A        return unsafeBuffer.getLong(0);%0A    %7D%0A%0A    @Benchmark%0A    public long getLong() %7B%0A        return buffer.getLong(0);%0A    %7D%0A%7D%0A

Add benchmark for HeapByteBuf implementations.