dev@grizzly.java.net

[Fwd: Performance comparision of Mina vs. java.nio ByteBuffer use]

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Wed, 04 Jul 2007 10:36:20 -0400

FYI.

-------- Original Message --------
Subject: Performance comparision of Mina vs. java.nio ByteBuffer use
Date: Wed, 04 Jul 2007 14:46:57 +0200
From: Michael Bauroth <michael.bauroth_at_falcom.de>
Reply-To: dev_at_mina.apache.org
Organization: Falcom GmbH
To: dev_at_mina.apache.org

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 ) ;)