Fixed JMH ByteBuf benchmark to avoid dead code elimination

Motivation:

The JMH doc suggests to use BlackHoles to avoid dead code elimination hence would be better to follow this best practice.

Modifications:

Each benchmark method is returning the ByteBuf/ByteBuffer to avoid the JVM to perform any dead code elimination.

Result:

The results are more reliable and comparable to the others provided by other ByteBuf benchmarks (eg HeapByteBufBenchmark)
This commit is contained in:
Francesco Nigro 2017-12-19 11:16:10 +01:00 committed by Norman Maurer
parent 94ab0dc442
commit 1cf2687244

View File

@ -54,27 +54,27 @@ public class ByteBufBenchmark extends AbstractMicrobenchmark {
} }
@Benchmark @Benchmark
public void setByteBufferHeap() { public ByteBuffer setByteBufferHeap() {
byteBuffer.put(0, BYTE); return byteBuffer.put(0, BYTE);
} }
@Benchmark @Benchmark
public void setByteBufferDirect() { public ByteBuffer setByteBufferDirect() {
directByteBuffer.put(0, BYTE); return directByteBuffer.put(0, BYTE);
} }
@Benchmark @Benchmark
public void setByteBufHeap() { public ByteBuf setByteBufHeap() {
buffer.setByte(0, BYTE); return buffer.setByte(0, BYTE);
} }
@Benchmark @Benchmark
public void setByteBufDirect() { public ByteBuf setByteBufDirect() {
directBuffer.setByte(0, BYTE); return directBuffer.setByte(0, BYTE);
} }
@Benchmark @Benchmark
public void setByteBufDirectPooled() { public ByteBuf setByteBufDirectPooled() {
directBufferPooled.setByte(0, BYTE); return directBufferPooled.setByte(0, BYTE);
} }
} }