package org.simantics.db.tests.performance.java; import gnu.trove.list.array.TByteArrayList; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Arrays; import org.simantics.db.testing.base.TestCommonPerf; public class BufferTest extends TestCommonPerf { public static void test() throws Exception { final boolean DEBUG = false; final int BUFFER_SIZE = 100000000; final int LOOP_SIZE = BUFFER_SIZE / 10; { ByteBuffer b = ByteBuffer.wrap(new byte[BUFFER_SIZE]); long start = System.nanoTime(); b.order(ByteOrder.LITTLE_ENDIAN); for(int i=0;i>> 8); arr[index++] = (byte)(i & 0xFF); arr[index++] = (byte)((i >>> 8) & 0xFF); arr[index++] = (byte)((i >>> 16) & 0xFF); arr[index++] = (byte)((i >>> 24) & 0xFF); } long duration3 = System.nanoTime() - start3; if (DEBUG) { System.err.println("took " + 1e-9*duration3); System.err.println(Arrays.hashCode(arr)); } } { TByteArrayList list = new TByteArrayList(BUFFER_SIZE); long start4 = System.nanoTime(); for(int i=0;i>> 8)); list.add((byte)(i & 0xFF)); list.add((byte)((i >>> 8) & 0xFF)); list.add((byte)((i >>> 16) & 0xFF)); list.add((byte)((i >>> 24) & 0xFF)); } long duration4 = System.nanoTime() - start4; if (DEBUG) { System.err.println("took " + 1e-9*duration4); System.err.println(list.hashCode()); } } { byte[] arr2 = new byte[BUFFER_SIZE]; long start5 = System.nanoTime(); for(int i=0;i>> 8); } static private void writeInt(byte[] bytes, int i) { bytes[byteIndex++] = (byte)(i & 0xFF); bytes[byteIndex++] = (byte)((i >>> 8) & 0xFF); bytes[byteIndex++] = (byte)((i >>> 16) & 0xFF); bytes[byteIndex++] = (byte)((i >>> 24) & 0xFF); } public static void main(String[] args) { try { test(); } catch (Exception e) { e.printStackTrace(); } } }