Hate to say this ... but this is a very poorly written micro-benchmark. :-(
It suffers from at least one major issue, there is no warm up loop to
remove JIT compilation interference. And, several additional potential
issues; gc may be occurring more in one case versus the other and
depending on how quickly this loop executes, 'currentTimeMillis()' on
some platforms only has resolution to about 7 milliseconds. We also
don't know which JIT compiler was being used or any other JVM command
line args.
But, we could certainly to do a "fair" comparison and submit the results :-)
charlie ...
Jeanfrancois Arcand wrote:
> 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 ) ;)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
>
--
Charlie Hunt
Java Performance Engineer
630.285.7708 x47708 (Internal)
<http://java.sun.com/docs/performance/>