@@ -0,0 +1,2277 @@
+/*%0A * Copyright 2017 Matt Sicker%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * 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,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.musigma.logging.jmh;%0A%0Aimport org.openjdk.jmh.annotations.Benchmark;%0Aimport org.openjdk.jmh.annotations.Scope;%0Aimport org.openjdk.jmh.annotations.Setup;%0Aimport org.openjdk.jmh.annotations.State;%0Aimport org.openjdk.jmh.runner.Runner;%0Aimport org.openjdk.jmh.runner.RunnerException;%0Aimport org.openjdk.jmh.runner.options.Options;%0Aimport org.openjdk.jmh.runner.options.OptionsBuilder;%0A%0Aimport java.nio.ByteBuffer;%0Aimport java.util.Random;%0A%0A/**%0A * Compares the performance of copying from different types of ByteBuffers into a byte array.%0A */%0A@State(Scope.Benchmark)%0Apublic class ByteBufferBenchmark %7B%0A%0A    private static final int BUFSIZ = 8192;%0A    private ByteBuffer heap = ByteBuffer.allocate(BUFSIZ);%0A    private ByteBuffer direct = ByteBuffer.allocateDirect(BUFSIZ);%0A    private byte%5B%5D buf = new byte%5BBUFSIZ%5D;%0A%0A    @Setup%0A    public void setup() %7B%0A        heap.clear();%0A        direct.clear();%0A        Random r = new Random();%0A        for (int i = 0; i %3C BUFSIZ; i++) %7B%0A            byte b = (byte) r.nextInt(256);%0A            heap.put(b);%0A            direct.put(b);%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    public ByteBuffer copyViaHeap() %7B%0A        heap.rewind();%0A        return heap.get(buf, 0, BUFSIZ);%0A    %7D%0A%0A    @Benchmark%0A    public ByteBuffer copyDirectly() %7B%0A        direct.rewind();%0A        return direct.get(buf, 0, BUFSIZ);%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws RunnerException %7B%0A        Options options = new OptionsBuilder()%0A            .include(ByteBufferBenchmark.class.getName())%0A            .warmupIterations(10)%0A            .measurementIterations(10)%0A            .forks(1)%0A            .build();%0A%0A        new Runner(options).run();%0A    %7D%0A%7D%0A

Add ByteBufferBenchmark