I tweaked your test code a little bit, and ran the VM with '-server'
option. With MINA 1.x, you will have to use
SimpleByteBufferAllocator. I used MINA 2.0 in the test, and found NIO
buffers and MINA buffers don't differ in performance.
public class Main {
public static void main(String args[]) throws Exception {
org.apache.mina.common.ByteBuffer mb =
org.apache.mina.common.ByteBuffer.allocate(100, false);
java.nio.ByteBuffer nb = java.nio.ByteBuffer.allocate(100);
byte[] tBytes = new byte[100];
for (;;) {
testMina(mb, tBytes);
testNio(nb, tBytes);
}
}
private static void testMina(org.apache.mina.common.ByteBuffer mb,
byte[] tBytes) {
long tStart = System.currentTimeMillis();
for ( int i = 10000000; i > 0 ; i--)
{
mb.get( tBytes );
mb.rewind();
}
long tStop = System.currentTimeMillis();
System.out.println( "M: " + (tStop - tStart) );
}
private static void testNio(java.nio.ByteBuffer nb, byte[] tBytes) {
long tStart = System.currentTimeMillis();
for ( int i = 10000000; i > 0 ; i--)
{
nb.get( tBytes );
nb.rewind();
}
long tStop = System.currentTimeMillis();
System.out.println( "N: " + (tStop - tStart) );
}
}
On 7/4/07, Michael Bauroth <[EMAIL PROTECTED]> wrote:
Hi,
I've made some performance tests while the last hours. My special
interest was the performance of non-direct ByteBuffer operations like an
simple get(byte[]). Here is a very short code sample:
import java.nio.ByteBuffer;
import com.sun.grizzly.util.ByteBufferFactory;
//import org.apache.mina.common.ByteBuffer;
public class Test
{
public static void main(String[] pArgs)
{
byte[] tBytes = new byte[ 100 ];
//ByteBuffer buf = ByteBuffer.allocate( 100, false );
ByteBuffer buf = ByteBufferFactory.allocateView( 7, false );
long tStart = System.currentTimeMillis();
for ( int i = 0; i < 10000000; i++)
{
buf.get( tBytes );
buf.rewind();
//buf.position( 0 );
}
long tStop = System.currentTimeMillis();
System.out.println( tStop - tStart );
}
}
It seems that the Mina buffers need twice the time against the use of
java.nio ByteBuffer directly (ByteBuffers which are constructed from
Grizzly ByteBufferFactory are also a little bit slower because of the
use of slice(), but only about 10%). You can check it simply if you use
mybuffer.buf().get(...) instead of mybuffer.get(...)
What happens here?
Best Regards
Michael
Btw.: rewind() is ~15% quicker then position( 0 ) ;)
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6