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%2FMapTest.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fperformance%2Fjava%2FMapTest.java;h=a03b9acb0cd98903bcecb84bb7d6152bfe96073e;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/MapTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/MapTest.java new file mode 100644 index 000000000..a03b9acb0 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/MapTest.java @@ -0,0 +1,67 @@ +package org.simantics.db.tests.performance.java; + +import gnu.trove.map.hash.TIntByteHashMap; + +import java.util.TreeMap; + +import org.simantics.db.testing.base.TestCommonPerf; + + +public class MapTest extends TestCommonPerf { + + public void a(TIntByteHashMap map, int i) { + byte test = (byte)i; + byte value = map.get(test); + if(value == 0) { + map.put(test, value); + } + } + + public void b(TreeMap map2, int i) { + Byte value = map2.get(i); + if(value == null) { + map2.put(i, value); + } + } + + public void test() throws Exception { + + TIntByteHashMap map = new TIntByteHashMap(); + + long start = System.nanoTime(); + for(int i=0;i<12000000;i++) { + byte test = (byte)i; + byte value = map.get(test); + if(value == 0) { + map.put(test, value); + } + } + long duration = System.nanoTime() - start; + System.err.println("took " + 1e-9*duration); + + TIntByteHashMap map2 = new TIntByteHashMap(); + long start2 = System.nanoTime(); + for(int i=0;i<10000000;i++) a(map2, i); + long duration2 = System.nanoTime() - start2; + System.err.println("took " + 1e-9*duration2); + + TreeMap map3 = new TreeMap(); + long start3 = System.nanoTime(); + for(int i=0;i<10000000;i++) { + Byte value = map3.get(i); + if(value == null) { + map3.put(i, value); + } + } + long duration3 = System.nanoTime() - start3; + System.err.println("took " + 1e-9*duration3); + + TreeMap map4 = new TreeMap(); + long start4 = System.nanoTime(); + for(int i=0;i<10000000;i++) b(map4, i); + long duration4 = System.nanoTime() - start4; + System.err.println("took " + 1e-9*duration4); + + } + +}