Skip to content

Instantly share code, notes, and snippets.

@normanmaurer
Created June 4, 2014 12:28
Show Gist options
  • Select an option

  • Save normanmaurer/808cd1999217295a16d2 to your computer and use it in GitHub Desktop.

Select an option

Save normanmaurer/808cd1999217295a16d2 to your computer and use it in GitHub Desktop.
@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