Skip to content

Commit

Permalink
Fix the inconsistencies between performance tests in ByteBufAllocator…
Browse files Browse the repository at this point in the history
…Benchmark

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
  • Loading branch information
trustin committed Jun 21, 2014
1 parent 36305d7 commit 87346d1
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,13 +88,21 @@ public void pooledDirectAllocAndFree() {

@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);
}
}

0 comments on commit 87346d1

Please sign in to comment.