import java.nio.ByteBuffer; public class BufferTest { public void foo() { ByteBuffer buf = ByteBuffer.allocate(35); long start = System.currentTimeMillis(); byte b1 = 73; byte b2 = 13; for (int i = 0; i < COUNT; i++) { b1 = buf.get(0); buf.put(0, b2); } long stop = System.currentTimeMillis(); System.out.println("Using get/put: " + (stop - start)); } public void foo2() { ByteBuffer buf = ByteBuffer.allocate(35); byte[] dbuf = buf.array(); long start = System.currentTimeMillis(); byte b1 = 73; byte b2 = 13; for (int i = 0; i < COUNT; i++) { b1 = dbuf[0]; dbuf[0] = b2; } long stop = System.currentTimeMillis(); System.out.println("Using array access: " + (stop - start)); } public static final int COUNT = 800000000; public static void main (String[] argv) { BufferTest test = new BufferTest(); test.foo(); test.foo2(); } }