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
public void setByteBufferHeap() {
byteBuffer.put(0, BYTE);
public ByteBuffer setByteBufferHeap() {
return byteBuffer.put(0, BYTE);
}
@Benchmark
public void setByteBufferDirect() {
directByteBuffer.put(0, BYTE);
public ByteBuffer setByteBufferDirect() {
return directByteBuffer.put(0, BYTE);
}
@Benchmark
public void setByteBufHeap() {
buffer.setByte(0, BYTE);
public ByteBuf setByteBufHeap() {
return buffer.setByte(0, BYTE);
}
@Benchmark
public void setByteBufDirect() {
directBuffer.setByte(0, BYTE);
public ByteBuf setByteBufDirect() {
return directBuffer.setByte(0, BYTE);
}
@Benchmark
public void setByteBufDirectPooled() {
directBufferPooled.setByte(0, BYTE);
public ByteBuf setByteBufDirectPooled() {
return directBufferPooled.setByte(0, BYTE);
}
}