From cb994dd92640367a0ce7c05e4d2c6df748386c51 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sat, 21 Jun 2014 13:27:28 +0900 Subject: [PATCH] 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 --- .../buffer/ByteBufAllocatorBenchmark.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/microbench/src/test/java/io/netty/microbench/buffer/ByteBufAllocatorBenchmark.java b/microbench/src/test/java/io/netty/microbench/buffer/ByteBufAllocatorBenchmark.java index a7295118ad..252d0d3b30 100644 --- a/microbench/src/test/java/io/netty/microbench/buffer/ByteBufAllocatorBenchmark.java +++ b/microbench/src/test/java/io/netty/microbench/buffer/ByteBufAllocatorBenchmark.java @@ -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); } }