Skip to content

Instantly share code, notes, and snippets.

@burtonator
Created June 28, 2013 04:53
Show Gist options
  • Save burtonator/5882533 to your computer and use it in GitHub Desktop.
Save burtonator/5882533 to your computer and use it in GitHub Desktop.
package io.netty.buffer;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
public class Test {
public static void test( ByteBuf buff ) {
System.out.printf( "----------------\n" );
List<Long> durations = new ArrayList<Long>();
// test filling it with bytes...
System.out.printf( "class impl: %s\n", buff.getClass().getName() );
for( int j = 0; j < 10; ++j ) {
long before = System.currentTimeMillis();
buff.writerIndex(0);
for( int i = 0; i < buff.capacity() / 4; ++i ) {
buff.writeInt( i );
}
long after = System.currentTimeMillis();
long duration = (after-before);
System.out.printf( "Duration: %,d ms\n", duration );
durations.add( duration );
System.gc();
}
long sum = 0;
for( long d : durations ) {
sum += d;
}
System.out.printf( "Final mean duration: %,d ms\n", sum / durations.size() );
}
public static void main(String[] args) {
System.out.printf( "This is just a test\n" );
int capacity = 500000000;
test( Unpooled.directBuffer(capacity) );
test( Unpooled.buffer(capacity) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment