+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<Integer, Byte> 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<Integer, Byte> map3 = new TreeMap<Integer, Byte>();
+ 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<Integer, Byte> map4 = new TreeMap<Integer, Byte>();
+ 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);
+
+ }
+
+}