package com.paritytrading.philadelphia.perf;

import static java.nio.charset.StandardCharsets.*;

import com.paritytrading.philadelphia.FIXTags;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;

@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(value = 3)
@State(Scope.Benchmark)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.SampleTime)
public class FIXTagsBenchmark {

    private ByteBuffer buffer;

    @Setup(Level.Iteration)
    public void prepare() {
        buffer = ByteBuffer.wrap("123=".getBytes(US_ASCII));
    }

    @Benchmark
    public void baseline() {
    }

    @Benchmark
    public long get() {
        long tag = FIXTags.get(buffer);

        buffer.flip();

        return tag;
    }

    @Benchmark
    public void put() {
        FIXTags.put(buffer, 123);

        buffer.flip();
    }

}

@@ -43,60 +43,8 @@
 f;%0A%0A
-import static java.nio.charset.StandardCharsets.*;%0A%0A
 impo
@@ -1017,57 +1017,164 @@
    b
-uffer = ByteBuffer.wrap(%22123=%22.getBytes(US_ASCII)
+yte%5B%5D bytes = new byte%5B%5D %7B '1', '2', '3', '=' %7D;%0A%0A        buffer = ByteBuffer.allocateDirect(bytes.length);%0A%0A        buffer.put(bytes);%0A        buffer.flip(
 );%0A 

Use direct byte buffer in 'FIXTagsBenchmark'