Unmapping MappedByteBuffer

Johannes.Lichtenberger Johannes.Lichtenberger at uni-konstanz.de
Fri Nov 2 21:32:35 PDT 2012


On 11/03/2012 05:28 AM, Johannes.Lichtenberger wrote:
> 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...

Ok, in this case probably doesn't make a lot of difference ;-)

kind regards,
Johannes



More information about the nio-dev mailing list