Created
June 4, 2014 12:28
-
-
Save normanmaurer/808cd1999217295a16d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @State(Scope.Benchmark) | |
| @Warmup(iterations = 25) | |
| @Measurement(iterations = 50) | |
| public class SwappedByteBufBenchmark extends AbstractMicrobenchmark { | |
| private final ByteBuf buffer = Unpooled.directBuffer(8); | |
| private final ByteBuf swappedByteBuf = new SwappedByteBuf(buffer); | |
| private final ByteBuf unsafeSwappedByteBuf = buffer.order(ByteOrder.LITTLE_ENDIAN); | |
| public SwappedByteBufBenchmark() { | |
| if (unsafeSwappedByteBuf.getClass().equals(SwappedByteBuf.class)) { | |
| throw new IllegalStateException("Should not use " + SwappedByteBuf.class.getSimpleName()); | |
| } | |
| } | |
| @Param({ "00000", "00256", "01024", "04096", "16384", "65536" }) | |
| public int size; | |
| @GenerateMicroBenchmark | |
| public void swappedByteBufSetInt() { | |
| swappedByteBuf.setLong(0, size); | |
| } | |
| @GenerateMicroBenchmark | |
| public void swappedByteBufSetShort() { | |
| swappedByteBuf.setShort(0, size); | |
| } | |
| @GenerateMicroBenchmark | |
| public void swappedByteBufSetLong() { | |
| swappedByteBuf.setLong(0, size); | |
| } | |
| @GenerateMicroBenchmark | |
| public void unsafeSwappedByteBufSetInt() { | |
| unsafeSwappedByteBuf.setInt(0, size); | |
| } | |
| @GenerateMicroBenchmark | |
| public void unsafeSwappedByteBufSetShort() { | |
| unsafeSwappedByteBuf.setShort(0, size); | |
| } | |
| @GenerateMicroBenchmark | |
| public void unsafeSwappedByteBufSetLong() { | |
| unsafeSwappedByteBuf.setLong(0, size); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment