Created
June 28, 2013 04:53
-
-
Save burtonator/5882533 to your computer and use it in GitHub Desktop.
This file contains 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
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