]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/MapTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / performance / java / MapTest.java
1 package org.simantics.db.tests.performance.java;
2
3 import gnu.trove.map.hash.TIntByteHashMap;
4
5 import java.util.TreeMap;
6
7 import org.simantics.db.testing.base.TestCommonPerf;
8
9
10 public class MapTest extends TestCommonPerf {
11
12         public void a(TIntByteHashMap map, int i) {
13                 byte test = (byte)i;
14                 byte value = map.get(test);
15                 if(value == 0) {
16                         map.put(test, value);
17                 }
18         }
19         
20         public void b(TreeMap<Integer, Byte> map2, int i) {
21                 Byte value = map2.get(i);
22                 if(value == null) {
23                         map2.put(i, value);
24                 }
25         }
26
27         public void test() throws Exception {
28
29                 TIntByteHashMap map = new TIntByteHashMap();
30                 
31                 long start = System.nanoTime();
32                 for(int i=0;i<12000000;i++) {
33                         byte test = (byte)i;
34                         byte value = map.get(test);
35                         if(value == 0) {
36                                 map.put(test, value);
37                         }
38                 }
39                 long duration = System.nanoTime() - start;
40                 System.err.println("took " + 1e-9*duration);
41
42                 TIntByteHashMap map2 = new TIntByteHashMap();
43                 long start2 = System.nanoTime();
44                 for(int i=0;i<10000000;i++) a(map2, i);
45                 long duration2 = System.nanoTime() - start2;
46                 System.err.println("took " + 1e-9*duration2);
47                 
48                 TreeMap<Integer, Byte> map3 = new TreeMap<Integer, Byte>();
49                 long start3 = System.nanoTime();
50                 for(int i=0;i<10000000;i++) {
51                         Byte value = map3.get(i);
52                         if(value == null) {
53                                 map3.put(i, value);
54                         }
55                 }
56                 long duration3 = System.nanoTime() - start3;
57                 System.err.println("took " + 1e-9*duration3);
58
59                 TreeMap<Integer, Byte> map4 = new TreeMap<Integer, Byte>();
60                 long start4 = System.nanoTime();
61                 for(int i=0;i<10000000;i++) b(map4, i);
62                 long duration4 = System.nanoTime() - start4;
63                 System.err.println("took " + 1e-9*duration4);
64                 
65         }
66
67 }