Add cursor benchmarks 40/72140/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 22 May 2018 02:05:33 +0000 (04:05 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 22 May 2018 07:01:20 +0000 (09:01 +0200)
Cursor operations are supposedly more efficient as they do not need
to go through YangInstanceIdentifier. Add a microbenchmark to test
that theory.

Change-Id: Ic98b5219bfe5629b0edf6f4cbf8265695afa25f0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
benchmarks/src/main/java/org/opendaylight/yangtools/yang/data/impl/tree/InMemoryDataTreeBenchmark.java

index 2978a58a2eb60ea31e9bc9e0cd60e2a591282cba..f833e70a6a748f9b1d65d4cd85ccf458e41818fc 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeM
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
@@ -143,6 +144,19 @@ public class InMemoryDataTreeBenchmark {
         commit(modification);
     }
 
+    @Benchmark
+    @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
+    @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
+    public void write100KSingleNodeWithOneInnerItemInOneCommitCursorBenchmark() throws DataValidationFailedException {
+        final CursorAwareDataTreeModification modification = begin();
+        try (DataTreeModificationCursor cursor = modification.createCursor(BenchmarkModel.OUTER_LIST_PATH)) {
+            for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
+                cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
+            }
+        }
+        commit(modification);
+    }
+
     @Benchmark
     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
@@ -165,6 +179,19 @@ public class InMemoryDataTreeBenchmark {
         commit(modification);
     }
 
+    @Benchmark
+    @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
+    @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
+    public void write50KSingleNodeWithTwoInnerItemsInOneCommitCursorBenchmark() throws DataValidationFailedException {
+        final CursorAwareDataTreeModification modification = begin();
+        try (DataTreeModificationCursor cursor = modification.createCursor(BenchmarkModel.OUTER_LIST_PATH)) {
+            for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
+                cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
+            }
+        }
+        commit(modification);
+    }
+
     @Benchmark
     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
@@ -187,6 +214,19 @@ public class InMemoryDataTreeBenchmark {
         commit(modification);
     }
 
+    @Benchmark
+    @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
+    @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
+    public void write10KSingleNodeWithTenInnerItemsInOneCommitCursorBenchmark() throws DataValidationFailedException {
+        final CursorAwareDataTreeModification modification = begin();
+        try (DataTreeModificationCursor cursor = modification.createCursor(BenchmarkModel.OUTER_LIST_PATH)) {
+            for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
+                cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
+            }
+        }
+        commit(modification);
+    }
+
     @Benchmark
     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)