segStore: Add benchmarks for sorted iterations
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 20 Oct 2016 19:12:40 +0000 (15:12 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Thu, 27 Oct 2016 14:48:02 +0000 (10:48 -0400)
Change-Id: Ia9c5d679ed87c0f03c1890f2477f376c35a874e4
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/83632
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
statesystem/org.eclipse.tracecompass.segmentstore.core.tests/perf/org/eclipse/tracecompass/analysis/timing/core/tests/store/SegmentStoreBenchmark.java

index c3de89caab044d97cdb048178587e2df043e99f5..1dc8c8aff3084f2b842ea8287efb214d42de36b2 100644 (file)
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertNotNull;
 import java.text.DecimalFormat;
 import java.text.Format;
 import java.util.Arrays;
+import java.util.Comparator;
 import java.util.Random;
 
 import org.eclipse.jdt.annotation.NonNull;
@@ -23,6 +24,7 @@ import org.eclipse.tracecompass.internal.segmentstore.core.treemap.TreeMapStore;
 import org.eclipse.tracecompass.segmentstore.core.BasicSegment;
 import org.eclipse.tracecompass.segmentstore.core.ISegment;
 import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
+import org.eclipse.tracecompass.segmentstore.core.SegmentComparators;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -193,6 +195,71 @@ public class SegmentStoreBenchmark {
         runIterateAddIterate(size, fuzz, name);
     }
 
+    /**
+     * Test adding elements in a random order then iterate over the list, this
+     * is an atypical degenerate use case.
+     */
+    @Test
+    public void test8AddFuzzyOrderThenIterateByStartTime() {
+        int size = 1000;
+        int[] fuzz = new int[size];
+        Random rng = new Random(10);
+        for (int i = 0; i < size; i++) {
+            fuzz[i] = rng.nextInt(1000);
+        }
+        String name = new Object() {
+        }.getClass().getEnclosingMethod().getName();
+        assertNotNull(name);
+        runIterateCompare(size, fuzz, name, SegmentComparators.INTERVAL_START_COMPARATOR);
+    }
+
+    /**
+     * Test adding elements in a random order then iterate over the list, this
+     * is an atypical degenerate use case.
+     */
+    @Test
+    public void test9AddFuzzyOrderThenIterateByEndTime() {
+        int size = 1000;
+        int[] fuzz = new int[size];
+        Random rng = new Random(10);
+        for (int i = 0; i < size; i++) {
+            fuzz[i] = rng.nextInt(1000);
+        }
+        String name = new Object() {
+        }.getClass().getEnclosingMethod().getName();
+        assertNotNull(name);
+        runIterateCompare(size, fuzz, name, SegmentComparators.INTERVAL_END_COMPARATOR);
+    }
+
+    /**
+     * Test adding elements in a random order then iterate over the list, this
+     * is an atypical degenerate use case.
+     */
+    @Test
+    public void testAAddFuzzyOrderThenIterateByDuration() {
+        int size = 1000;
+        int[] fuzz = new int[size];
+        Random rng = new Random(10);
+        for (int i = 0; i < size; i++) {
+            fuzz[i] = rng.nextInt(1000);
+        }
+        String name = new Object() {
+        }.getClass().getEnclosingMethod().getName();
+        assertNotNull(name);
+        runIterateCompare(size, fuzz, name, SegmentComparators.INTERVAL_LENGTH_COMPARATOR);
+    }
+
+    private void runIterateCompare(int size, int[] fuzz, String method, @NonNull Comparator<@NonNull ISegment> comparator) {
+        long start = System.nanoTime();
+        populate(size, fuzz, fSegStore);
+        long startTime = fuzz[0];
+        long endTime = fSegStore.size() - 1 + fuzz[fSegStore.size() % size];
+        iterateCompare(startTime, endTime, fSegStore, comparator);
+        long end = System.nanoTime();
+        long duration = end - start;
+        outputResults(duration, method);
+    }
+
     private void run(int size, int[] fuzz, String method) {
         long duration = populate(size, fuzz, fSegStore);
         outputResults(duration, method);
@@ -250,6 +317,14 @@ public class SegmentStoreBenchmark {
         return shutupCompilerWarnings;
     }
 
+    private static Object iterateCompare(long startTime, long endTime, ISegmentStore<@NonNull ISegment> store, @NonNull Comparator<@NonNull ISegment> comparator) {
+        Object shutupCompilerWarnings = null;
+        for (ISegment elem : store.getIntersectingElements(startTime, endTime, comparator)) {
+            shutupCompilerWarnings = elem;
+        }
+        return shutupCompilerWarnings;
+    }
+
     private static void populate(int size, int[] fuzz, ISegmentStore<@NonNull ISegment> store, int count) {
         for (int i = 0; i < count; i++) {
             long start = i + fuzz[i % size];
This page took 0.025464 seconds and 5 git commands to generate.