felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1690696 - /felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/BigResolutionTest.java
Date Mon, 13 Jul 2015 15:16:07 GMT
Author: gnodet
Date: Mon Jul 13 15:16:07 2015
New Revision: 1690696

URL: http://svn.apache.org/r1690696
Log:
[FELIX-4942] Improve the big resolution test to help testing for performance

Modified:
    felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/BigResolutionTest.java

Modified: felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/BigResolutionTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/BigResolutionTest.java?rev=1690696&r1=1690695&r2=1690696&view=diff
==============================================================================
--- felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/BigResolutionTest.java
(original)
+++ felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/BigResolutionTest.java
Mon Jul 13 15:16:07 2015
@@ -53,21 +53,49 @@ import org.osgi.resource.Wiring;
 import org.osgi.service.resolver.HostedCapability;
 import org.osgi.service.resolver.ResolveContext;
 
+import static org.junit.Assert.assertEquals;
+
 public class BigResolutionTest {
 
     @Test
     @Ignore
     public void testResolutionSpeed() throws Exception {
+        ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_INFO));
+
         ResolveContext rc = buildResolutionContext();
 
-        ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_INFO));
-        for (int i = 0; i < 10; i++) {
+        System.out.println("Warming up...");
+        Map<Resource, List<Wire>> wires = resolver.resolve(rc);
+        resolver.resolve(rc);
+
+        System.out.println("Running...");
+        RunningStat stats = new RunningStat();
+        for (int i = 1; i <= 100; i++) {
+            System.gc();
+            Thread.sleep(100);
             System.gc();
-            long t0 = System.currentTimeMillis();
-            resolver.resolve(rc);
-            long t1 = System.currentTimeMillis();
-            System.out.println("Resolver took " + (t1 - t0) + " ms");
+            Thread.sleep(100);
+            long t0 = System.nanoTime();
+            Map<Resource, List<Wire>> newWires = resolver.resolve(rc);
+            long t1 = System.nanoTime();
+            double dt = (t1 - t0) * 1E-6;
+            System.out.println("Resolver took " + String.format("%7.2f", dt) + " ms");
+            stats.put(dt);
+            assertEquals(wires, newWires);
+
+            if (i % 10 == 0) {
+                System.out.println();
+                System.out.println("Summary");
+                System.out.println("    Min:    " + String.format("%7.2f", stats.getMin())
+ " ms");
+                System.out.println("    Max:    " + String.format("%7.2f", stats.getMax())
+ " ms");
+                System.out.println("    Avg:    " + String.format("%7.2f", stats.getAverage())
+ " ms");
+                System.out.println("    StdDev: " + String.format("%7" +
+                        ".2f", stats.getStdDev() / stats.getAverage() * 100.0) + " %");
+                System.out.println();
+                stats = new RunningStat();
+            }
         }
+
     }
 
     @Test
@@ -372,4 +400,48 @@ public class BigResolutionTest {
         }
     }
 
+    public static class RunningStat {
+
+        private int count = 0;
+        private double min = Double.MAX_VALUE;
+        private double max = 0.0;
+        private double average = 0.0;
+        private double pwrSumAvg = 0.0;
+        private double stdDev = 0.0;
+
+        /**
+         * Incoming new values used to calculate the running statistics
+         *
+         * @param value the new value
+         */
+        public void put(double value) {
+
+            count++;
+            average += (value - average) / count;
+            pwrSumAvg += (value * value - pwrSumAvg) / count;
+            stdDev = Math.sqrt((pwrSumAvg * count - count * average * average) / (count -
1));
+            min = Math.min(min, value);
+            max = Math.max(max, value);
+
+        }
+
+        public double getMin() {
+            return min;
+        }
+
+        public double getMax() {
+            return max;
+        }
+
+        public double getAverage() {
+
+            return average;
+        }
+
+        public double getStdDev() {
+
+            return Double.isNaN(stdDev) ? 0.0 : stdDev;
+        }
+
+    }
 }



Mime
View raw message