From cea1776eb4b541427c1c77a67cb95fa39595c0ac Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 1 Jan 2017 15:25:19 +0100 Subject: [PATCH] BUG-7464: cleanup and disable instantiation speed test 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 --- .../triemap/TestInstantiationSpeed.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/third-party/triemap/src/test/java/org/opendaylight/yangtools/triemap/TestInstantiationSpeed.java b/third-party/triemap/src/test/java/org/opendaylight/yangtools/triemap/TestInstantiationSpeed.java index 7eafe1e524..9424d07224 100644 --- a/third-party/triemap/src/test/java/org/opendaylight/yangtools/triemap/TestInstantiationSpeed.java +++ b/third-party/triemap/src/test/java/org/opendaylight/yangtools/triemap/TestInstantiationSpeed.java @@ -15,40 +15,53 @@ */ 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); } } -- 2.36.6