X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fperformance%2Fjava%2FBufferTest.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fperformance%2Fjava%2FBufferTest.java;h=f9d2cbb4fe8c57abf549bd305949ba103f5d89bc;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/BufferTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/BufferTest.java new file mode 100644 index 000000000..f9d2cbb4f --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/BufferTest.java @@ -0,0 +1,125 @@ +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(); + } + } + +}