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 36305d7dce
commit 87346d14a8

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[] pooledHeapBuffers = 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" })
public int size;
@ -86,13 +88,21 @@ public class ByteBufAllocatorBenchmark extends AbstractMicrobenchmark {
@Benchmark
public void defaultPooledHeapAllocAndFree() {
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(size);
buffer.release();
int idx = rand.nextInt(defaultPooledHeapBuffers.length);
ByteBuf oldBuf = defaultPooledHeapBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
defaultPooledHeapBuffers[idx] = PooledByteBufAllocator.DEFAULT.heapBuffer(size);
}
@Benchmark
public void defaultPooledDirectAllocAndFree() {
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.directBuffer(size);
buffer.release();
int idx = rand.nextInt(defaultPooledDirectBuffers.length);
ByteBuf oldBuf = defaultPooledDirectBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
defaultPooledDirectBuffers[idx] = PooledByteBufAllocator.DEFAULT.directBuffer(size);
}
}