tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twil...@apache.org
Subject [26/50] [abbrv] tinkerpop git commit: shouldBeFaster() in both RepeatUnrollStrategyTest and IdentityRemovalStrategyTest now do parameter sweeps and test a broader range of behaviors.
Date Fri, 08 Jul 2016 12:39:44 GMT
shouldBeFaster() in both RepeatUnrollStrategyTest and IdentityRemovalStrategyTest now do parameter
sweeps and test a broader range of behaviors.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e6071c0e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e6071c0e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e6071c0e

Branch: refs/heads/TINKERPOP-1254
Commit: e6071c0e445061c003cd8a68803a635ff2610fad
Parents: 857deab
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Tue Jun 28 15:23:53 2016 -0600
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Tue Jun 28 15:23:53 2016 -0600

----------------------------------------------------------------------
 .../IdentityRemovalStrategyTest.java            | 50 +++++++++---
 .../optimization/RepeatUnrollStrategyTest.java  | 81 ++++++++------------
 2 files changed, 72 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6071c0e/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IdentityRemovalStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IdentityRemovalStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IdentityRemovalStrategyTest.java
index 3a84813..c5099f9 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IdentityRemovalStrategyTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IdentityRemovalStrategyTest.java
@@ -20,6 +20,7 @@ package org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization;
 
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalStrategies;
 import org.apache.tinkerpop.gremlin.util.TimeUtil;
@@ -29,6 +30,7 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
 import java.util.Arrays;
+import java.util.Random;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -81,27 +83,51 @@ public class IdentityRemovalStrategyTest {
     }
 
     public static class NonParameterizedTests {
+
+        private static final Random RANDOM = new Random();
+
         @Test
         public void shouldBeFaster() {
 
             final int startSize = 1000;
-            final int clockRuns = 1000;
+            final int clockRuns = 2000;
+            final int maxIdentities = 10;
+            final int minIdentities = 3;
             final Integer[] starts = new Integer[startSize];
             for (int i = 0; i < startSize; i++) {
                 starts[i] = i;
             }
 
-            final Runnable original = () -> __.inject(starts).identity().identity().identity().identity().iterate();
-
-            final Runnable optimized = () -> {
-                final Traversal<Integer, Integer> traversal = __.inject(starts).identity().identity().identity().identity();
-                traversal.asAdmin().setStrategies(traversal.asAdmin().getStrategies().clone().addStrategies(IdentityRemovalStrategy.instance()));
-                traversal.iterate();
-            };
-
-            //System.out.println(TimeUtil.clock(clockRuns, original) + "---" + TimeUtil.clock(clockRuns,optimized));
-            assertTrue(TimeUtil.clock(clockRuns, original) > TimeUtil.clock(clockRuns,
optimized));
-            assertTrue(TimeUtil.clock(clockRuns, optimized) < TimeUtil.clock(clockRuns,
original));
+            for (int i = minIdentities; i < maxIdentities; i++) {
+                final int numberOfIdentities = i;
+                final Runnable original = () -> {
+                    final GraphTraversal<Integer, Integer> traversal = __.inject(starts);
+                    for (int j = 0; j < numberOfIdentities; j++) {
+                        traversal.identity();
+                    }
+                    traversal.iterate();
+                };
+
+                final TraversalStrategies strategies = new DefaultTraversalStrategies();
+                strategies.addStrategies(IdentityRemovalStrategy.instance());
+                final Runnable optimized = () -> {
+                    final GraphTraversal<Integer, Integer> traversal = __.inject(starts);
+                    for (int j = 0; j < numberOfIdentities; j++) {
+                        traversal.identity();
+                    }
+                    traversal.asAdmin().setStrategies(strategies);
+                    traversal.iterate();
+                };
+
+                //System.out.println(TimeUtil.clock(clockRuns, original) + "---" + TimeUtil.clock(clockRuns,
optimized));
+                if (RANDOM.nextBoolean()) {
+                    assertTrue(TimeUtil.clock(clockRuns, original) > TimeUtil.clock(clockRuns,
optimized));
+                    assertTrue(TimeUtil.clock(clockRuns, optimized) < TimeUtil.clock(clockRuns,
original));
+                } else {
+                    assertTrue(TimeUtil.clock(clockRuns, optimized) < TimeUtil.clock(clockRuns,
original));
+                    assertTrue(TimeUtil.clock(clockRuns, original) > TimeUtil.clock(clockRuns,
optimized));
+                }
+            }
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6071c0e/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RepeatUnrollStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RepeatUnrollStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RepeatUnrollStrategyTest.java
index 3d47a10..91ab2ae 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RepeatUnrollStrategyTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RepeatUnrollStrategyTest.java
@@ -101,56 +101,43 @@ public class RepeatUnrollStrategyTest {
     public static class NonParameterizedTests {
 
         @Test
-        public void shouldBeFasterWithUniqueStream() {
+        public void shouldBeFaster() {
             final int startSize = 1000;
             final int clockRuns = 1000;
-            final Integer[] starts = new Integer[startSize];
-            for (int i = 0; i < startSize; i++) {
-                starts[i] = i; // 1000 unique objects
+            for (int i = 100; i <= startSize; i = i + 200) {
+                final Integer[] starts = new Integer[startSize];
+                for (int j = 0; j < startSize; j++) {
+                    starts[j] = j % i;
+                }
+                assertEquals(i, new HashSet<>(Arrays.asList(starts)).size());
+                ///
+                for (int j = 2; j < 6; j++) {
+                    final int times = j;
+                    final Supplier<Long> original = () -> __.inject(starts).repeat(__.identity()).times(times).<Long>sum().next();
+
+                    final TraversalStrategies strategies = new DefaultTraversalStrategies();
+                    strategies.addStrategies(RepeatUnrollStrategy.instance());
+                    final Supplier<Long> optimized = () -> {
+                        final Traversal<Integer, Long> traversal = __.inject(starts).repeat(__.identity()).times(times).sum();
+                        traversal.asAdmin().setStrategies(strategies);
+                        return traversal.next();
+                    };
+
+                    final Pair<Double, Long> originalResult;
+                    final Pair<Double, Long> optimizedResult;
+                    if (RANDOM.nextBoolean()) {
+                        originalResult = TimeUtil.clockWithResult(clockRuns, original);
+                        optimizedResult = TimeUtil.clockWithResult(clockRuns, optimized);
+                    } else {
+                        optimizedResult = TimeUtil.clockWithResult(clockRuns, optimized);
+                        originalResult = TimeUtil.clockWithResult(clockRuns, original);
+                    }
+
+                    // System.out.println(originalResult + "---" + optimizedResult);
+                    assertEquals(originalResult.getValue1(), optimizedResult.getValue1());
+                    assertTrue(originalResult.getValue0() > optimizedResult.getValue0());
+                }
             }
-            assertEquals(startSize, new HashSet<>(Arrays.asList(starts)).size());
-            clockTraversals(starts, clockRuns);
-        }
-
-        @Test
-        public void shouldBeFasterWithDuplicateStream() {
-            final int startSize = 1000;
-            final int clockRuns = 1000;
-            final int uniques = 100;
-            final Integer[] starts = new Integer[startSize];
-            for (int i = 0; i < startSize; i++) {
-                starts[i] = i % uniques; // 100 unique objects
-            }
-            assertEquals(uniques, new HashSet<>(Arrays.asList(starts)).size());
-            clockTraversals(starts, clockRuns);
-        }
-
-        private void clockTraversals(final Integer[] starts, final int clockRuns) {
-            final int times = RANDOM.nextInt(4) + 2;
-            assertTrue(times > 1 && times < 6);
-            final Supplier<Long> original = () -> __.inject(starts).repeat(__.identity()).times(times).<Long>sum().next();
-
-            final TraversalStrategies strategies = new DefaultTraversalStrategies();
-            strategies.addStrategies(RepeatUnrollStrategy.instance());
-            final Supplier<Long> optimized = () -> {
-                final Traversal<Integer, Long> traversal = __.inject(starts).repeat(__.identity()).times(times).sum();
-                traversal.asAdmin().setStrategies(strategies);
-                return traversal.next();
-            };
-
-            final Pair<Double, Long> originalResult;
-            final Pair<Double, Long> optimizedResult;
-            if (RANDOM.nextBoolean()) {
-                originalResult = TimeUtil.clockWithResult(clockRuns, original);
-                optimizedResult = TimeUtil.clockWithResult(clockRuns, optimized);
-            } else {
-                optimizedResult = TimeUtil.clockWithResult(clockRuns, optimized);
-                originalResult = TimeUtil.clockWithResult(clockRuns, original);
-            }
-
-            // System.out.println(originalResult + "---" + optimizedResult);
-            assertEquals(originalResult.getValue1(), optimizedResult.getValue1());
-            assertTrue(originalResult.getValue0() > optimizedResult.getValue0());
         }
     }
 }


Mime
View raw message