package org.jvirtanen.philadelphia.perf;

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

import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
import org.jvirtanen.philadelphia.FIXTags;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
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.TearDown;

@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class FIXTagsBenchmark {

    private ByteBuffer buffer;

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

    @TearDown(Level.Invocation)
    public void tearDown() {
        buffer.flip();
    }

    @Benchmark
    @BenchmarkMode(Mode.SampleTime)
    public long get() {
        return FIXTags.get(buffer);
    }

    @Benchmark
    @BenchmarkMode(Mode.SampleTime)
    public void put() {
        FIXTags.put(buffer, 123);
    }

}

@@ -850,99 +850,8 @@
  %7D%0A%0A
-    @TearDown(Level.Invocation)%0A    public void tearDown() %7B%0A        buffer.flip();%0A    %7D%0A%0A
     
@@ -933,14 +933,18 @@
     
-return
+long tag =
  FIX
@@ -960,16 +960,61 @@
 buffer);
+%0A%0A        buffer.flip();%0A%0A        return tag;
 %0A    %7D%0A%0A
@@ -1121,16 +1121,40 @@
 r, 123);
+%0A%0A        buffer.flip();
 %0A    %7D%0A%0A

Remove invocation level teardown from FIX tags benchmark