Skip to content

Instantly share code, notes, and snippets.

@attilapiros
Created June 19, 2018 18:38
Show Gist options
  • Save attilapiros/730d67b62317d14f5fd0f6779adea245 to your computer and use it in GitHub Desktop.
Save attilapiros/730d67b62317d14f5fd0f6779adea245 to your computer and use it in GitHub Desktop.
@Test
public void speedTest() {
int n = 500;
int oneBuffSize = 100000;
System.out.println("n = " + n);
byte buffArray[][] = new byte[n][];
for (int j = 0; j < n; j++) {
byte buff0[] = new byte[oneBuffSize];
for (int i = 0; i < oneBuffSize; i++) {
buff0[i] = (byte) (i % 12);
}
buffArray[j] = buff0;
}
System.out.println("duration221 = " + durationOfSend(n, Unpooled.wrappedBuffer(buffArray), oneBuffSize));
System.out.println("duration221.new = " + durationOfNewSend(n, Unpooled.wrappedBuffer(buffArray), oneBuffSize));
System.out.println("duration230 = " + durationOfSend(n, Unpooled.wrappedBuffer(n, buffArray), oneBuffSize));
System.out.println("duration230.new = " + durationOfNewSend(n, Unpooled.wrappedBuffer(n, buffArray), oneBuffSize));
}
private long durationOfSend(int n, ByteBuf bb, int oneBuffSize) {
long start = System.currentTimeMillis();
for (int j = 0; j < n; j++) {
bb.nioBuffer();
bb.skipBytes(oneBuffSize);
}
return System.currentTimeMillis() - start;
}
private long durationOfNewSend(int n, ByteBuf bb, int oneBuffSize) {
long start = System.currentTimeMillis();
for (int j = 0; j < n; j++) {
bb.nioBuffer(0, oneBuffSize-1);
bb.skipBytes(oneBuffSize);
}
return System.currentTimeMillis() - start;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment