Unmapping MappedByteBuffer (original) (raw)
Johannes.Lichtenberger Johannes.Lichtenberger at uni-konstanz.de
Fri Nov 2 21:28:05 PDT 2012
- Previous message: Unmapping MappedByteBuffer
- Next message: Unmapping MappedByteBuffer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 11/03/2012 03:59 AM, Zhong Yu wrote:> static public void test1(int cap, int repeat) throws Exception
{ int sum=0; long time = System.currentTimeMillis(); ByteBuffer bb = ByteBuffer.allocateDirect(cap); for(int r=0; r<repeat; r++) { for(int i=0; i<cap; i++) { sum += bb.get(i); } } time = System.currentTimeMillis() - time; System.out.printf("time=%,d, sum=%,d %n", time, sum); } static public void test2(int cap, int repeat) throws Exception { int sum=0; long time = System.currentTimeMillis(); ByteBuffer bb0 = ByteBuffer.allocateDirect(cap); SingleOwnerByteBuffer bb = new SingleOwnerByteBuffer(bb0); bb.own(); for(int r=0; r<repeat; r++) { for(int i=0; i<cap; i++) { sum += bb.get(i); } } bb.disown(); time = System.currentTimeMillis() - time; System.out.printf("time=%,d, sum=%,d %n", time, sum); }
}
Is the use of System.currentTimeMills() instead of System.nanoTime() deliberately used? I'd use nanoTime() as always suggested (because currentTimeMills() depends on wallclock time which is sometimes corrected). Otherwise it might even cause negative values in some cases...
kind regards, Johannes
- Previous message: Unmapping MappedByteBuffer
- Next message: Unmapping MappedByteBuffer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]