Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lindberg2009-12-02 21:58:36 +0000
committerHenrik Lindberg2009-12-02 21:58:36 +0000
commit71280944eb3b232400bf7f9e48c21730e326351b (patch)
tree9f912b6fecfb216d2f6883ec417ea27a27eee8f5
parent871ff72b141cc905d76c3471446eea3bcc6c8186 (diff)
downloadrt.equinox.p2-71280944eb3b232400bf7f9e48c21730e326351b.tar.gz
rt.equinox.p2-71280944eb3b232400bf7f9e48c21730e326351b.tar.xz
rt.equinox.p2-71280944eb3b232400bf7f9e48c21730e326351b.zip
[294691] Capability Index function added (increased performance) and more tests.
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/EvaluatorTest.java6
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/PerformanceTest.java103
2 files changed, 53 insertions, 56 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/EvaluatorTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/EvaluatorTest.java
index a2b044d14..8a51d4e08 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/EvaluatorTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/EvaluatorTest.java
@@ -36,7 +36,7 @@ import org.osgi.framework.Filter;
public class EvaluatorTest extends AbstractProvisioningTest {
private static final ExpressionParser parser = new ExpressionParser();
- private static final VariableScope dummyScope = new VariableScope();
+ private static final VariableScope dummyScope = VariableScope.ROOT;
public void testArguments() throws Exception {
Expression expr = parser.parsePredicate("'a' == $0 && 'b' == $1 && 'c' == $2");
@@ -111,8 +111,8 @@ public class EvaluatorTest extends AbstractProvisioningTest {
// indexes for the parameters
Variable item = Variable.createEach("item");
- Expression cmp1 = new Equals(new Member(item, "id"), new KeyedParameter("id"));
- Expression cmp2 = new Equals(new At(new Member(item, "properties"), new KeyedParameter("propKey")), new KeyedParameter("propValue"));
+ Expression cmp1 = new Equals(Member.createDynamicMember(item, "id"), new KeyedParameter("id"));
+ Expression cmp2 = new Equals(new At(Member.createDynamicMember(item, "properties"), new KeyedParameter("propKey")), new KeyedParameter("propValue"));
Variable everything = Variable.EVERYTHING;
LambdaExpression lambda = new LambdaExpression(new And(new Expression[] {cmp1, cmp2}), item);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/PerformanceTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/PerformanceTest.java
index abffa2af0..c91d99fc5 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/PerformanceTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/PerformanceTest.java
@@ -11,10 +11,10 @@
package org.eclipse.equinox.p2.tests.ql;
import java.net.URI;
-import java.util.Hashtable;
-import java.util.Iterator;
+import java.util.*;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
+import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.internal.p2.director.Slicer;
import org.eclipse.equinox.internal.p2.director.app.Activator;
import org.eclipse.equinox.internal.provisional.p2.metadata.*;
@@ -38,16 +38,16 @@ public class PerformanceTest extends AbstractProvisioningTest {
long tradQueryMS = 0;
long exprQueryMS = 0;
- for (int i = 0; i < 10; ++i) {
+ for (int i = 0; i < 5; ++i) {
long start = System.currentTimeMillis();
- for (int idx = 0; idx < 100; ++idx) {
+ for (int idx = 0; idx < 80; ++idx) {
result = repo.query(capabilityQuery, new Collector(), new NullProgressMonitor());
assertEquals(result.size(), 487);
}
tradQueryMS += (System.currentTimeMillis() - start);
start = System.currentTimeMillis();
- for (int idx = 0; idx < 100; ++idx) {
+ for (int idx = 0; idx < 80; ++idx) {
result = repo.query(predicateQuery, new Collector(), new NullProgressMonitor());
assertEquals(result.size(), 487);
}
@@ -55,10 +55,7 @@ public class PerformanceTest extends AbstractProvisioningTest {
}
System.out.println("CapabilityQuery took: " + tradQueryMS + " milliseconds");
System.out.println("PredicateQuery took: " + exprQueryMS + " milliseconds");
-
- // Assert that expression query is not worse off then 4 / 3 ratio (should typically
- // be better then that.
- assertTrue(tradQueryMS * 4 > exprQueryMS * 3);
+ System.out.println();
}
public void testCapabilityQueryPerformance2() throws Exception {
@@ -75,16 +72,16 @@ public class PerformanceTest extends AbstractProvisioningTest {
long tradQueryMS = 0;
long exprQueryMS = 0;
- for (int i = 0; i < 10; ++i) {
+ for (int i = 0; i < 5; ++i) {
long start = System.currentTimeMillis();
- for (int idx = 0; idx < 100; ++idx) {
+ for (int idx = 0; idx < 80; ++idx) {
result = repo.query(capabilityQuery, new Collector(), new NullProgressMonitor());
assertEquals(result.size(), 446);
}
tradQueryMS += (System.currentTimeMillis() - start);
start = System.currentTimeMillis();
- for (int idx = 0; idx < 100; ++idx) {
+ for (int idx = 0; idx < 80; ++idx) {
result = repo.query(predicateQuery, new Collector(), new NullProgressMonitor());
assertEquals(result.size(), 446);
}
@@ -92,10 +89,7 @@ public class PerformanceTest extends AbstractProvisioningTest {
}
System.out.println("CapabilityQuery took: " + tradQueryMS + " milliseconds");
System.out.println("PredicateQuery took: " + exprQueryMS + " milliseconds");
-
- // Assert that expression query is not worse off then 4 / 3 ratio (should typically
- // be better then that.
- assertTrue(tradQueryMS * 4 > exprQueryMS * 3);
+ System.out.println();
}
public void testIUPropertyQueryPerformance() throws Exception {
@@ -108,16 +102,16 @@ public class PerformanceTest extends AbstractProvisioningTest {
long tradQueryMS = 0;
long exprQueryMS = 0;
- for (int i = 0; i < 10; ++i) {
+ for (int i = 0; i < 5; ++i) {
long start = System.currentTimeMillis();
- for (int idx = 0; idx < 100; ++idx) {
+ for (int idx = 0; idx < 80; ++idx) {
result = repo.query(propertyQuery, new Collector(), new NullProgressMonitor());
assertEquals(result.size(), 965);
}
tradQueryMS += (System.currentTimeMillis() - start);
start = System.currentTimeMillis();
- for (int idx = 0; idx < 100; ++idx) {
+ for (int idx = 0; idx < 80; ++idx) {
result = repo.query(predicateQuery, new Collector(), new NullProgressMonitor());
assertEquals(result.size(), 965);
}
@@ -125,10 +119,7 @@ public class PerformanceTest extends AbstractProvisioningTest {
}
System.out.println("IUPropertyQuery took: " + tradQueryMS + " milliseconds");
System.out.println("PredicateQuery took: " + exprQueryMS + " milliseconds");
-
- // Assert that expression query is not worse off then 4 / 3 ratio (should typically
- // be better then that.
- assertTrue(tradQueryMS * 4 > exprQueryMS * 3);
+ System.out.println();
}
public void testSlicerPerformance() throws Exception {
@@ -142,38 +133,36 @@ public class PerformanceTest extends AbstractProvisioningTest {
Iterator itor = c.iterator();
assertTrue(itor.hasNext());
IInstallableUnit[] roots = new IInstallableUnit[] {(IInstallableUnit) itor.next()};
- Slicer slicer = new Slicer(repo, env, false);
-
- long startTime = System.currentTimeMillis();
- IQueryable slice = slicer.slice(roots, new NullProgressMonitor());
-
- c = slice.query(new MatchQuery() {
- public boolean isMatch(Object value) {
- return true;
- }
- }, new Collector(), new NullProgressMonitor());
- long slicerTime = System.currentTimeMillis() - startTime;
-
- assertEquals(c.size(), 411);
- System.out.print("Slicer took: ");
- System.out.println(slicerTime);
- IQuery query = new ExpressionQuery(//
- "$0.traverse(set(), _, {requirementsCache, parent | select(" + //
- "parent.requiredCapabilities.unique(requirementsCache).select(rc | rc.filter == null || $1 ~= filter(rc.filter)), _," + //
- "{rcs, child | rcs.exists(rc | child ~= rc)})})", roots, env);
-
- startTime = System.currentTimeMillis();
- c = repo.query(query, new Collector(), new NullProgressMonitor());
- long traverseTime = System.currentTimeMillis() - startTime;
-
- assertEquals(c.size(), 411);
- System.out.print("Traverse expression took: ");
+ IQuery query = new ExpressionQuery("" + //
+ "$0.traverse(capabilityIndex(everything), _, {index, parent | " + //
+ "index.satisfiesAny(parent.requiredCapabilities.select(rc | rc.filter == null || $1 ~= filter(rc.filter)))})", roots, env);
+
+ long sliceTime = 0;
+ long traverseTime = 0;
+ IQueryable slice = null;
+ for (int idx = 0; idx < 20; ++idx) {
+ long startTime = System.currentTimeMillis();
+ c = repo.query(query, new Collector(), new NullProgressMonitor());
+ traverseTime += (System.currentTimeMillis() - startTime);
+ assertEquals(c.size(), 411);
+
+ startTime = System.currentTimeMillis();
+ Slicer slicer = new Slicer(new QueryableArray(gatherAvailableInstallableUnits(repo)), env, false);
+ slice = slicer.slice(roots, new NullProgressMonitor());
+ c = slice.query(new MatchQuery() {
+ public boolean isMatch(Object value) {
+ return true;
+ }
+ }, new Collector(), new NullProgressMonitor());
+ sliceTime += (System.currentTimeMillis() - startTime);
+ assertEquals(c.size(), 411);
+ }
+ System.out.print("20 * Slicing took: ");
+ System.out.println(sliceTime);
+ System.out.print("20 * Indexed Traverse expression took: ");
System.out.println(traverseTime);
-
- // Assert that expression query is at least 3/1 ratio ratio (should typically
- // be better then that.
- assertTrue(traverseTime * 3 < slicerTime);
+ System.out.println();
}
private IMetadataRepository getMDR(String uri) throws Exception {
@@ -184,4 +173,12 @@ public class PerformanceTest extends AbstractProvisioningTest {
return metadataManager.loadRepository(metadataRepo, new NullProgressMonitor());
}
+
+ private IInstallableUnit[] gatherAvailableInstallableUnits(IQueryable queryable) {
+ ArrayList list = new ArrayList();
+ Collector matches = queryable.query(InstallableUnitQuery.ANY, new Collector(), null);
+ for (Iterator it = matches.iterator(); it.hasNext();)
+ list.add(it.next());
+ return (IInstallableUnit[]) list.toArray(new IInstallableUnit[list.size()]);
+ }
}

Back to the top