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 2016/05/06 21:52:52 UTC

svn commit: r1742651 - /uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTest.java

Author: schor
Date: Fri May  6 21:52:52 2016
New Revision: 1742651

URL: http://svn.apache.org/viewvc?rev=1742651&view=rev
Log:
[UIMA-4674] add disabled cas copier performance test

Modified:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTest.java

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTest.java?rev=1742651&r1=1742650&r2=1742651&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTest.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/test/GrowingTheCasTest.java Fri May  6 21:52:52 2016
@@ -183,6 +183,91 @@ public class GrowingTheCasTest extends T
     jcas= null;
   }
 
+  public void tstCasCopierPerf() {
+//  Properties props = System.getProperties();
+//  for (Map.Entry es : props.entrySet()) {
+//    System.out.format("JVM Prop %s: %s%n",  es.getKey(), es.getValue());
+//  }
+
+//  System.out.format("JVM total memory: %,d, JVM Max Mem: %,d%n", Runtime.getRuntime().totalMemory(), Runtime.getRuntime().maxMemory());
+  File textFile = JUnitExtension.getFile("data/moby.txt");
+  String text = null;
+  try {
+    text = FileUtils.file2String(textFile, "utf-8");
+  } catch (IOException e) {
+    e.printStackTrace();
+    assertTrue(false);
+  }
+  StringBuffer buf = new StringBuffer(text.length() * 10);
+  for (int i = 0; i < 10; i++) {
+    buf.append(text);
+  }
+  jcas = null;
+  try {
+    jcas = this.ae.newJCas();
+  } catch (ResourceInitializationException e) {
+    e.printStackTrace();
+    assertTrue(false);
+  }
+  text = buf.toString();
+  jcas.setDocumentText(text);
+  int numberOfSentences = 0;
+  int numberOfTokens = 0;
+  try {
+//    long time = System.currentTimeMillis();
+    this.ae.process(jcas);
+//    time = System.currentTimeMillis() - time;
+//    System.out.println("Time for large CAS: " + new TimeSpan(time));
+    numberOfSentences = jcas.getAnnotationIndex(Sentence.type).size();
+    numberOfTokens = jcas.getAnnotationIndex(Token.type).size();
+    System.out.println("Moby * 10, nbr of sentences = " + numberOfSentences);
+    System.out.println("Moby * 10, nbr of tokens = " + numberOfTokens);
+  } catch (AnalysisEngineProcessException e) {
+    e.printStackTrace();
+    assertTrue(false);
+  }
+  
+//  // performance testing of "unordered" iterators
+//  for (int i = 0; i < 10; i++) {
+//    timeIt(i);
+//  }
+  
+  // performance testing of CasCopier
+  
+  // create a destination CAS
+  CAS destCas;
+  try {
+    destCas = this.ae.newCAS();
+  } catch (ResourceInitializationException e) {
+    e.printStackTrace();
+    assertTrue(false);
+    return;  // to avoid compile problems
+  }
+  CAS srcCas = jcas.getCas();
+
+  CasCopier copier;
+  // do the copy
+  long shortest = Long.MAX_VALUE;
+  int i = 0;
+  for (; i < 200; i++) {  // uncomment for perf test.  was more than 5x faster than version 2.6.0
+    destCas.reset();
+    long startTime = System.nanoTime();
+    copier = new CasCopier(srcCas, destCas);
+    copier.copyCasView(srcCas, true);
+    long time = (System.nanoTime() - startTime)/ 1000;
+    if (time < shortest) {
+      shortest = time;
+      System.out.format("CasCopier speed for Moby is %,d microseconds on iteration %,d%n", shortest, i);
+    }
+  }
+  
+  // verify copy
+  CasComparer.assertEquals(srcCas, destCas);
+
+//  ((JCasImpl)jcas).showJfsFromCaddrHistogram();
+  jcas= null;
+}
+
   private void timeIt(int i) {
     FSIterator<FeatureStructure> it = jcas.getIndexRepository().getAllIndexedFS(jcas.getCasType(Annotation.type));   
     int c = 0;