import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
import org.testng.annotations.Test;
+import intervalstore.api.IntervalStoreI;
+
public class IntervalStoreTest
{
@Test(groups = "Functional")
assertTrue(store.findOverlaps(36, 100, overlaps).isEmpty());
assertTrue(store.findOverlaps(1, 9, overlaps).isEmpty());
}
-}
+
+ /**
+ * Compares alternative IntervalStoreI implementations for time to add an
+ * interval then query, at a range of different scales of N (the number of
+ * stored features).
+ */
+ @Test(groups = "Timing")
+ public void testAddAndQueryTiming()
+ {
+ IntervalStoreI<SimpleFeature> store = new intervalstore.impl.IntervalStore<>();
+ System.out.println("IntervalStoreJ");
+ testAddAndQueryTiming(store);
+
+ System.out.println("\nnonc.IntervalStore");
+ store = new intervalstore.nonc.IntervalStore<>();
+ testAddAndQueryTiming(store);
+ }
+
+ /**
+ * Populates the store with intervals, then logs the time taken to add an
+ * interval then query, at a range of different scales of N (the number of
+ * stored features).
+ *
+ * @param store
+ */
+ private void testAddAndQueryTiming(IntervalStoreI<SimpleFeature> store)
+ {
+ final int seqlen = 100000; // e.g. length of gene sequence
+ final int repeats = 20;
+ final int K = 1000;
+ final int warmups = 5;
+ final int[] scales = new int[] { 10 * K, 100 * K, K * K };
+
+ Random r = new Random(732); // fixed seed = repeatable test
+ int counter = 0; // to ensure a distinct description for each feature
+
+ System.out.println("Scale\titeration\tmicrosecs");
+
+ for (int scale : scales)
+ {
+ /*
+ * add 'scale' features to the store
+ */
+ for (int i = 0; i < scale; i++)
+ {
+ SimpleFeature sf = makeFeature(seqlen, r, counter);
+ counter++;
+ store.add(sf);
+ }
+
+ /*
+ * do "add then query" and log the time taken for the query
+ * we ignore the first 5 repetitions as 'warmups'
+ */
+ long total = 0L;
+ for (int i = 0; i < repeats + warmups; i++)
+ {
+ SimpleFeature sf = makeFeature(seqlen, r, counter);
+ store.add(sf);
+ long t1 = System.nanoTime();
+ store.findOverlaps(10, 20);
+ long elapsed = System.nanoTime() - t1;
+ if (i >= warmups)
+ {
+ total += elapsed;
+ System.out.println(
+ String.format("%d\t%d\t%d", scale, i - warmups,
+ elapsed / K));
+ }
+ }
+ System.out.println("average " + (total / (K * repeats)));
+ }
+ }
+
+ SimpleFeature makeFeature(final int seqlen, Random r, int counter)
+ {
+ int i1 = r.nextInt(seqlen);
+ int i2 = r.nextInt(seqlen);
+ int from = Math.min(i1, i2);
+ int to = Math.max(i1, i2);
+ SimpleFeature sf = new SimpleFeature(from, to, "desc" + counter);
+ return sf;
+ }
+}
\ No newline at end of file