BUG-7464: Reformat source code
[yangtools.git] / third-party / triemap / src / test / java / org / opendaylight / yangtools / triemap / TestInstantiationSpeed.java
1 package org.opendaylight.yangtools.triemap;
2
3 import org.junit.Test;
4
5 public class TestInstantiationSpeed {
6     private static final int COUNT = 1000000;
7     private static final int ITERATIONS = 10;
8     private static final int WARMUP = 20;
9
10     private static long runIteration() {
11         final TrieMap<?, ?>[] maps = new TrieMap<?, ?>[COUNT];
12         final long start = System.nanoTime();
13
14         for (int i = 0; i < COUNT; ++i) {
15             maps[i] = TrieMap.empty();
16         }
17
18         final long stop = System.nanoTime();
19         return stop - start;
20     }
21
22     @Test
23     public void testInstantiation() {
24
25         for (int i = 0; i < WARMUP; ++i) {
26             final long time = runIteration();
27             System.out.println(String.format("Warmup %s took %sns (%sns)", i, time, time / COUNT));
28         }
29
30         long acc = 0;
31         for (int i = 0; i < ITERATIONS; ++i) {
32             final long time = runIteration();
33             System.out.println(String.format("Iteration %s took %sns (%sns)", i, time, time / COUNT));
34             acc += time;
35         }
36
37         System.out.println("Instantiation cost " + acc / ITERATIONS / COUNT + "ns");
38     }
39 }