BUG-7464: cleanup and disable instantiation speed test 03/49903/9
authorRobert Varga <rovarga@cisco.com>
Sun, 1 Jan 2017 14:25:19 +0000 (15:25 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 10 Jan 2017 19:02:44 +0000 (19:02 +0000)
Remove use of System.out and use a Guava stopwatch. This
test takes some time and is not really useful, hence disable
it.

Change-Id: Ib4b09b8e53e319230178c7898d7a2d14e4e2c1a0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
third-party/triemap/src/test/java/org/opendaylight/yangtools/triemap/TestInstantiationSpeed.java

index 7eafe1e52435c6c303fe1bd72f0da6d63de4516c..9424d072246c907b6f0b5bea8a00c06a68ff669c 100644 (file)
  */
 package org.opendaylight.yangtools.triemap;
 
+import com.google.common.base.Stopwatch;
+import java.util.concurrent.TimeUnit;
+import org.junit.Ignore;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class TestInstantiationSpeed {
+    private static final Logger LOG = LoggerFactory.getLogger(TestInstantiationSpeed.class);
     private static final int COUNT = 1000000;
     private static final int ITERATIONS = 10;
-    private static final int WARMUP = 20;
+    private static final int WARMUP = 10;
 
-    private static long runIteration() {
+    private static Stopwatch runIteration() {
         final TrieMap<?, ?>[] maps = new TrieMap<?, ?>[COUNT];
-        final long start = System.nanoTime();
 
+        final Stopwatch watch = Stopwatch.createStarted();
         for (int i = 0; i < COUNT; ++i) {
             maps[i] = new TrieMap<>();
         }
+        watch.stop();
 
-        final long stop = System.nanoTime();
-        return stop - start;
+        // Do not allow optimizations
+        LOG.trace("Maps: {}", (Object) maps);
+        return watch;
     }
 
+    private static long elapsedToNs(final Stopwatch watch) {
+        return watch.elapsed(TimeUnit.NANOSECONDS) / COUNT;
+    }
+
+    @Ignore
     @Test
     public void testInstantiation() {
 
         for (int i = 0; i < WARMUP; ++i) {
-            final long time = runIteration();
-            System.out.println(String.format("Warmup %s took %sns (%sns)", i, time, time / COUNT));
+            final Stopwatch time = runIteration();
+            LOG.debug("Warmup {} took {} ({} ns)", i, time, elapsedToNs(time));
         }
 
         long acc = 0;
         for (int i = 0; i < ITERATIONS; ++i) {
-            final long time = runIteration();
-            System.out.println(String.format("Iteration %s took %sns (%sns)", i, time, time / COUNT));
-            acc += time;
+            final Stopwatch time = runIteration();
+            LOG.debug("Iteration {} took {} ({} ns)", i, time, elapsedToNs(time));
+            acc += time.elapsed(TimeUnit.NANOSECONDS);
         }
 
-        System.out.println("Instantiation cost " + acc / ITERATIONS / COUNT + "ns");
+        LOG.info("Instantiation cost {} ns", acc / ITERATIONS / COUNT);
     }
 }