From 8bcf90a3d856f5dfc3fd0a3ea3ecc79894be5c45 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 22 May 2018 04:05:33 +0200 Subject: [PATCH] Add cursor benchmarks 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 --- .../impl/tree/InMemoryDataTreeBenchmark.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/benchmarks/src/main/java/org/opendaylight/yangtools/yang/data/impl/tree/InMemoryDataTreeBenchmark.java b/benchmarks/src/main/java/org/opendaylight/yangtools/yang/data/impl/tree/InMemoryDataTreeBenchmark.java index 2978a58a2e..f833e70a6a 100644 --- a/benchmarks/src/main/java/org/opendaylight/yangtools/yang/data/impl/tree/InMemoryDataTreeBenchmark.java +++ b/benchmarks/src/main/java/org/opendaylight/yangtools/yang/data/impl/tree/InMemoryDataTreeBenchmark.java @@ -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) -- 2.36.6