You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2013/11/07 19:41:29 UTC
svn commit: r1539757 -
/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/IndexRepositoryTest.java
Author: schor
Date: Thu Nov 7 18:41:29 2013
New Revision: 1539757
URL: http://svn.apache.org/r1539757
Log:
add test case measuring timing for lots of fs adds/removes, in various orders.
Modified:
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/IndexRepositoryTest.java
Modified: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/IndexRepositoryTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/IndexRepositoryTest.java?rev=1539757&r1=1539756&r2=1539757&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/IndexRepositoryTest.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/IndexRepositoryTest.java Thu Nov 7 18:41:29 2013
@@ -21,8 +21,10 @@ package org.apache.uima.cas.test;
import junit.framework.TestCase;
import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIndex;
import org.apache.uima.cas.FSIndexRepository;
import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.TypeSystem;
@@ -79,4 +81,109 @@ public class IndexRepositoryTest extends
iter2.next();
assertFalse(iter.hasNext());
}
+
+ public void testSetIndex() throws Exception {
+ Feature beginFeat = this.typeSystem.getFeatureByFullName(CASTestSetup.TOKEN_TYPE + ":begin");
+ // create an instance of an annotation type
+ Type tokenTypeType = this.typeSystem.getType(CASTestSetup.TOKEN_TYPE);
+ FeatureStructure tokenTypeFs1 = this.cas.createFS(tokenTypeType);
+ assertTrue(tokenTypeFs1 instanceof AnnotationFS);
+ tokenTypeFs1.setIntValue(beginFeat, 17);
+
+ FeatureStructure tokenTypeFs2 = this.cas.createFS(tokenTypeType);
+ assertTrue(tokenTypeFs2 instanceof AnnotationFS);
+ tokenTypeFs2.setIntValue(beginFeat, 17);
+
+ cas.addFsToIndexes(tokenTypeFs1);
+ cas.addFsToIndexes(tokenTypeFs2);
+
+ FSIndexRepository ir = cas.getIndexRepository();
+ FSIndex<FeatureStructure> index = ir.getIndex(CASTestSetup.ANNOT_SET_INDEX);
+ assertEquals(index.size(), 1);
+
+ index = ir.getIndex(CASTestSetup.ANNOT_SORT_INDEX);
+ assertEquals(index.size(), 2);
+
+ }
+
+ public static int NBR_ITEMS = 40000;
+
+ public void testRemovalSpeed() throws Exception {
+ // create an instance of an annotation type
+ Feature beginFeat = this.typeSystem.getFeatureByFullName(CASTestSetup.TOKEN_TYPE + ":begin");
+ Type fsType = this.typeSystem.getType(CASTestSetup.TOKEN_TYPE);
+ FeatureStructure[] fsa = new FeatureStructure[NBR_ITEMS];
+ // create 40000 tokens
+ for (int i = 0; i < fsa.length; i++) {
+ fsa[i] = this.cas.createFS(fsType);
+ fsa[i].setIntValue(beginFeat, i);
+ }
+
+ // warmup and jit
+ timeAdd2Indexes(fsa);
+ timeRemoveFromIndexes(fsa);
+
+ long a2i = timeAdd2Indexes(fsa);
+ long rfi = timeRemoveFromIndexes(fsa);
+
+ long a2i2 = timeAdd2Indexes(fsa);
+ long rfir = timeRemoveFromIndexesReverse(fsa);
+
+ System.out.format("Timing add/remv from indexes: add1: %,d msec, add2: %,d msec, rmv: %,d msec, rmvReversed: %,d msec%n",
+ a2i, a2i2, rfi, rfir);
+// big loop for doing profiling by hand and checking space recovery by hand
+
+// for (int i = 0; i < 10000; i++) {
+// timeAdd2Indexes(fsa);
+// timeRemoveFromIndexesReverse(fsa);
+// }
+ }
+
+ public void testRemovalSpeedBagAlone() throws Exception {
+ // create an instance of an non-annotation type
+ Type fsType = this.typeSystem.getType(CASTestSetup.TOKEN_TYPE_TYPE);
+ FeatureStructure[] fsa = new FeatureStructure[NBR_ITEMS];
+ // create 40000 token-types
+ for (int i = 0; i < fsa.length; i++) {
+ fsa[i] = this.cas.createFS(fsType);
+ }
+
+ // warmup and jit
+ timeAdd2Indexes(fsa);
+ timeRemoveFromIndexes(fsa);
+
+ long a2i = timeAdd2Indexes(fsa);
+ long rfi = timeRemoveFromIndexes(fsa);
+
+ long a2i2 = timeAdd2Indexes(fsa);
+ long rfir = timeRemoveFromIndexesReverse(fsa);
+
+ System.out.format("Timing add/remv from bag indexes: add1: %,d msec, add2: %,d msec, rmv: %,d msec, rmvReversed: %,d msec%n",
+ a2i, a2i2, rfi, rfir);
+ }
+
+ private long timeAdd2Indexes (FeatureStructure[] fsa) {
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < fsa.length; i++) {
+ cas.addFsToIndexes(fsa[i]);
+ }
+ return System.currentTimeMillis() - start;
+ }
+
+ private long timeRemoveFromIndexes (FeatureStructure[] fsa) {
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < fsa.length; i++) {
+ cas.removeFsFromIndexes(fsa[i]);
+ }
+ return System.currentTimeMillis() - start;
+ }
+
+ private long timeRemoveFromIndexesReverse (FeatureStructure[] fsa) {
+ long start = System.currentTimeMillis();
+ for (int i = fsa.length -1; i >= 0; i--) {
+ cas.removeFsFromIndexes(fsa[i]);
+ }
+ return System.currentTimeMillis() - start;
+ }
+
}