Fix the inconsistencies between performance tests in ByteBufAllocatorBenchmark

Motivation:

default*() tests are performing a test in a different way, and they must be same with other tests.

Modification:

Make sure default*() tests are same with the others

Result:

Easier to compare default and non-default allocators
This commit is contained in:
Trustin Lee 2014-06-21 13:27:28 +09:00
parent 004ffbad90
commit cb994dd926

View File

@ -40,6 +40,8 @@ public class ByteBufAllocatorBenchmark extends AbstractMicrobenchmark {
private static final ByteBuf[] unpooledDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS]; private static final ByteBuf[] unpooledDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] pooledHeapBuffers = new ByteBuf[MAX_LIVE_BUFFERS]; private static final ByteBuf[] pooledHeapBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] pooledDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS]; private static final ByteBuf[] pooledDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] defaultPooledHeapBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] defaultPooledDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
@Param({ "00000", "00256", "01024", "04096", "16384", "65536" }) @Param({ "00000", "00256", "01024", "04096", "16384", "65536" })
public int size; public int size;
@ -86,13 +88,21 @@ public class ByteBufAllocatorBenchmark extends AbstractMicrobenchmark {
@Benchmark @Benchmark
public void defaultPooledHeapAllocAndFree() { public void defaultPooledHeapAllocAndFree() {
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(size); int idx = rand.nextInt(defaultPooledHeapBuffers.length);
buffer.release(); ByteBuf oldBuf = defaultPooledHeapBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
defaultPooledHeapBuffers[idx] = PooledByteBufAllocator.DEFAULT.heapBuffer(size);
} }
@Benchmark @Benchmark
public void defaultPooledDirectAllocAndFree() { public void defaultPooledDirectAllocAndFree() {
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.directBuffer(size); int idx = rand.nextInt(defaultPooledDirectBuffers.length);
buffer.release(); ByteBuf oldBuf = defaultPooledDirectBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
defaultPooledDirectBuffers[idx] = PooledByteBufAllocator.DEFAULT.directBuffer(size);
} }
} }