aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-12-08 19:30:26 -0800
committerJon Bratseth <bratseth@yahoo-inc.com>2016-12-08 19:30:26 -0800
commit65feef43135153d5ec3b0dcc911d928cb13089d2 (patch)
tree2ae8263f1842b0806b4eb82a8dc1cc7ba28b66a9 /vespajlib
parentdf60e2017d759701078095d91d2c42f382c46046 (diff)
Benchmark indexed join
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/TensorType.java9
-rw-r--r--vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java38
2 files changed, 34 insertions, 13 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
index 8f99553277c..0e1e91c60d5 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
@@ -297,6 +297,15 @@ public class TensorType {
return add(dimension);
}
+ public Builder dimension(String name, Dimension.Type type) {
+ switch (type) {
+ case mapped : mapped(name); break;
+ case indexedUnbound : indexedUnbound(name); break;
+ default : throw new IllegalArgumentException("This can not create a dimension of type " + type);
+ }
+ return this;
+ }
+
public TensorType build() {
// TODO: Support that
if (containsMappedDimension(dimensions.values()) && containsIndexedDimension(dimensions.values()))
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java
index 7b1c07562c6..ff5e8823999 100644
--- a/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java
+++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java
@@ -13,13 +13,13 @@ public class TensorFunctionBenchmark {
private final static Random random = new Random();
- public double benchmark(int iterations, List<Tensor> modelVectors) {
- Tensor queryVector = generateVectors(1, 300).get(0);
+ public double benchmark(int iterations, List<Tensor> modelVectors, TensorType.Dimension.Type dimensionType) {
+ Tensor queryVector = generateVectors(1, 300, dimensionType).get(0);
dotProduct(queryVector, modelVectors, 10); // warmup
long startTime = System.currentTimeMillis();
dotProduct(queryVector, modelVectors, iterations);
long totalTime = System.currentTimeMillis() - startTime;
- return totalTime / iterations;
+ return (double)totalTime / (double)iterations;
}
private double dotProduct(Tensor tensor, List<Tensor> tensors, int iterations) {
@@ -38,13 +38,13 @@ public class TensorFunctionBenchmark {
largest = dotProduct;
}
}
- System.out.println(largest);
return largest;
}
- private static List<Tensor> generateVectors(int vectorCount, int vectorSize) {
+ private static List<Tensor> generateVectors(int vectorCount, int vectorSize,
+ TensorType.Dimension.Type dimensionType) {
List<Tensor> tensors = new ArrayList<>();
- TensorType type = new TensorType.Builder().mapped("x").build();
+ TensorType type = new TensorType.Builder().dimension("x", dimensionType).build();
for (int i = 0; i < vectorCount; i++) {
MapTensor.Builder builder = new MapTensor.Builder(type);
for (int j = 0; j < vectorSize; j++) {
@@ -55,9 +55,10 @@ public class TensorFunctionBenchmark {
return tensors;
}
- private static List<Tensor> generateVectorsInOneTensor(int vectorCount, int vectorSize) {
+ private static List<Tensor> generateMatrix(int vectorCount, int vectorSize,
+ TensorType.Dimension.Type dimensionType) {
List<Tensor> tensors = new ArrayList<>();
- TensorType type = new TensorType.Builder().mapped("i").mapped("x").build();
+ TensorType type = new TensorType.Builder().dimension("i", dimensionType).dimension("x", dimensionType).build();
MapTensor.Builder builder = new MapTensor.Builder(type);
for (int i = 0; i < vectorCount; i++) {
for (int j = 0; j < vectorSize; j++) {
@@ -71,18 +72,29 @@ public class TensorFunctionBenchmark {
return tensors; // only one tensor in the list.
}
+
+
public static void main(String[] args) {
+ double time;
+
+ // ---------------- Mapped:
// Was: 150 ms
// After adding type: 300 ms
// After sorting dimensions: 100 ms
// After special-casing single space: 4 ms
- double timeperJoin = new TensorFunctionBenchmark().benchmark(100, generateVectors(100, 300));
-
+ time = new TensorFunctionBenchmark().benchmark(1000, generateVectors(100, 300, TensorType.Dimension.Type.mapped), TensorType.Dimension.Type.mapped);
+ System.out.printf("Mapped vectors, time per join: %1$8.3f ms\n", time);
// This benchmark should be as fast as fast as the previous. Currently it is not by a factor of 600
- double timePerJoinOneTensor = new TensorFunctionBenchmark().benchmark(20, generateVectorsInOneTensor(100, 300));
+ time = new TensorFunctionBenchmark().benchmark(20, generateMatrix(100, 300, TensorType.Dimension.Type.mapped), TensorType.Dimension.Type.mapped);
+ System.out.printf("Mapped matrix, time per join: %1$8.3f ms\n", time);
- System.out.println("Time per join: " + timeperJoin + " ms");
- System.out.println("Time per join, one tensor: " + timePerJoinOneTensor + " ms");
+ // ---------------- Indexed:
+ // Was: 3 ms
+ time = new TensorFunctionBenchmark().benchmark(1000, generateVectors(100, 300, TensorType.Dimension.Type.indexedUnbound),TensorType.Dimension.Type.indexedUnbound);
+ System.out.printf("Indexed vectors, time per join: %1$8.3f ms\n", time);
+ // This benchmark should be as fast as fast as the previous. Currently it is not by a factor of 600
+ time = new TensorFunctionBenchmark().benchmark(20, generateMatrix(100, 300, TensorType.Dimension.Type.indexedUnbound), TensorType.Dimension.Type.indexedUnbound);
+ System.out.printf("Indexed matrix, time per join: %1$8.3f ms\n", time);
}
}