summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-01-04 11:33:11 +0100
committerJon Bratseth <bratseth@yahoo-inc.com>2017-01-04 11:33:11 +0100
commit3a99092a16b72ce32a2f4da4ef92c18a1b0b4cbf (patch)
tree99f0d4919f17af0bc09a250f10c8d4895c52ccef /vespajlib
parent7c6a4a06ed1aa3bb7201bab70f330139da1dcc6a (diff)
Move order check out of inner loop
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java17
-rw-r--r--vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java47
2 files changed, 21 insertions, 43 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java
index 3e747819b7b..d7f00f2d6f2 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java
@@ -170,12 +170,17 @@ public class Join extends PrimitiveTensorFunction {
Iterator<Map.Entry<TensorAddress, Double>> superspace, int superspaceSize,
boolean reversedArgumentOrder, Tensor.Builder builder) {
int joinedLength = Math.min(subspaceSize, superspaceSize);
- for (int i = 0; i < joinedLength; i++) {
- Double subvalue = subspace.next();
- Map.Entry<TensorAddress, Double> supercell = superspace.next();
- builder.cell(supercell.getKey(),
- reversedArgumentOrder ? combinator.applyAsDouble(supercell.getValue(), subvalue)
- : combinator.applyAsDouble(subvalue, supercell.getValue()));
+ if (reversedArgumentOrder) {
+ for (int i = 0; i < joinedLength; i++) {
+ Map.Entry<TensorAddress, Double> supercell = superspace.next();
+ builder.cell(supercell.getKey(), combinator.applyAsDouble(supercell.getValue(), subspace.next()));
+ }
+ }
+ else {
+ for (int i = 0; i < joinedLength; i++) {
+ Map.Entry<TensorAddress, Double> supercell = superspace.next();
+ builder.cell(supercell.getKey(), combinator.applyAsDouble(subspace.next(), supercell.getValue()));
+ }
}
}
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java
index 9b34780a6fc..56787dddbde 100644
--- a/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java
+++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java
@@ -105,71 +105,44 @@ public class TensorFunctionBenchmark {
double time;
// ---------------- Mapped with extra space (sidesteps current special-case optimizations):
- // Initial: 450 ms
- // - Now: 350 ms
+ // 420 ms
time = new TensorFunctionBenchmark().benchmark(20, vectors(100, 300, TensorType.Dimension.Type.mapped), TensorType.Dimension.Type.mapped, true);
System.out.printf("Mapped vectors, x space time per join: %1$8.3f ms\n", time);
- // Initial: 900 ms
- // - Now: 700 ms
+ // 770 ms
time = new TensorFunctionBenchmark().benchmark(20, matrix(100, 300, TensorType.Dimension.Type.mapped), TensorType.Dimension.Type.mapped, true);
System.out.printf("Mapped matrix, x space time per join: %1$8.3f ms\n", time);
// ---------------- Mapped:
- // Initial: 150 ms
- // - After adding type: 300 ms
- // - After sorting dimensions: 100 ms
- // - After special-casing single space: 2.4 ms
+ // 2.7 ms
time = new TensorFunctionBenchmark().benchmark(5000, vectors(100, 300, TensorType.Dimension.Type.mapped), TensorType.Dimension.Type.mapped, false);
System.out.printf("Mapped vectors, time per join: %1$8.3f ms\n", time);
- // Initial: 760 ms
- // - After special-casing subspace: 13 ms
- // - Now: 7 ms
+ // 7 ms
time = new TensorFunctionBenchmark().benchmark(500, matrix(100, 300, TensorType.Dimension.Type.mapped), TensorType.Dimension.Type.mapped, false);
System.out.printf("Mapped matrix, time per join: %1$8.3f ms\n", time);
// ---------------- Indexed (unbound) with extra space (sidesteps current special-case optimizations):
- // Initial: 1900 ms
- // - After moving to cell iterators: 1100
- // - Now: 1300
+ // 1700 ms
time = new TensorFunctionBenchmark().benchmark(20, vectors(100, 300, TensorType.Dimension.Type.indexedUnbound), TensorType.Dimension.Type.indexedUnbound, true);
System.out.printf("Indexed vectors, x space time per join: %1$8.3f ms\n", time);
- // Initial: 2200 ms
- // - After moving to cell iterators: 1300
- // - Now: 1550
+ // 1900 ms
time = new TensorFunctionBenchmark().benchmark(20, matrix(100, 300, TensorType.Dimension.Type.indexedUnbound), TensorType.Dimension.Type.indexedUnbound, true);
System.out.printf("Indexed matrix, x space time per join: %1$8.3f ms\n", time);
// ---------------- Indexed unbound:
- // Initial: 718 ms
- // - After special casing join: 3.6 ms
- // - After special-casing reduce: 0.80 ms
- // - After create IndexedTensor without builder: 0.4 ms
- // - After double-array backing: 0.09 ms
+ // 0.14 ms
time = new TensorFunctionBenchmark().benchmark(50000, vectors(100, 300, TensorType.Dimension.Type.indexedUnbound), TensorType.Dimension.Type.indexedUnbound, false);
System.out.printf("Indexed unbound vectors, time per join: %1$8.3f ms\n", time);
- // Initial: 3500 ms
- // - After special-casing subspace: 25 ms
- // - After moving to iterators: 7.7 ms
- // - After indexed subspace join algorithm: 6
- // - After passing sized: 3.7 ms
- // - After creating int tensor address: 2.5 ms
- // - After using int address to get ints directly: 0.93 ms
+ // 0.89 ms
time = new TensorFunctionBenchmark().benchmark(5000, matrix(100, 300, TensorType.Dimension.Type.indexedUnbound), TensorType.Dimension.Type.indexedUnbound, false);
System.out.printf("Indexed unbound matrix, time per join: %1$8.3f ms\n", time);
// ---------------- Indexed bound:
- // Initial: 0.09 ms
+ // 0.14 ms
time = new TensorFunctionBenchmark().benchmark(50000, vectors(100, 300, TensorType.Dimension.Type.indexedBound), TensorType.Dimension.Type.indexedBound, false);
System.out.printf("Indexed bound vectors, time per join: %1$8.3f ms\n", time);
- // Initial: 25 ms
- // - After moving to iterators: 7.7 ms
- // - After indexed subspace join algorithm: 6
- // - After passing sized: 3.7 ms
- // - After creating int tensor address: 2.8 ms
- // - After using int address to get ints directly: 0.93 ms
+ // 0.88 ms
time = new TensorFunctionBenchmark().benchmark(5000, matrix(100, 300, TensorType.Dimension.Type.indexedBound), TensorType.Dimension.Type.indexedBound, false);
System.out.printf("Indexed bound matrix, time per join: %1$8.3f ms\n", time);
-
}
}