Permalink
Browse files

add a test for testing the comp time of batched addDocs()

  • Loading branch information...
1 parent f3099c2 commit bf13927e136470ad5425522014514913324b824e @hyan committed Dec 1, 2010
Showing with 80 additions and 20 deletions.
  1. +80 −20 test/com/kamikaze/test/perf/PForDeltaPerfTest.java
@@ -135,35 +135,44 @@ public static void main(String args[]) throws Exception {
public static void doTests(PerfTests testObj, METHODS method, int[] numDocs) throws Exception
{
int batchSize = 256;
- int tryTimes = 2;
+ int tryTimes = 10;
testObj.reset(numDocs);
+ boolean onlyTestBatchComp = false;
System.out.println("tryTimes: " + tryTimes);
for (int i = 0; i < tryTimes; i++)
{
System.out.println("");
System.out.println("");
System.out.println("Round " + i);
System.out.println("");
- testObj.init(batchSize);
- switch(method)
+ if(!onlyTestBatchComp)
{
- case IPAND:
- testObj.testCompareIntArrayAndPForDeltaWithBaseForAndIntersection();
- break;
- case COMPDECOMP:
- testObj.testCompSizeAndDecompSpeedOfNextDoc();
- break;
- case AND:
- testObj.testAndIntersections();
- break;
- case FIND:
- testObj.testFind();
- break;
- case SERIAL:
- testObj.testSerializationFileStrm();
- break;
+ testObj.init(batchSize);
+ switch(method)
+ {
+ case IPAND:
+ testObj.testCompareIntArrayAndPForDeltaWithBaseForAndIntersection();
+ break;
+ case COMPDECOMP:
+ testObj.testCompSizeAndDecompSpeedOfNextDoc();
+ break;
+ case AND:
+ testObj.testAndIntersections();
+ break;
+ case FIND:
+ testObj.testFind();
+ break;
+ case SERIAL:
+ testObj.testSerializationFileStrm();
+ break;
+ }
}
+ else
+ {
+ testObj.initAndTestCompTime(batchSize);
+ }
+
//testObj.testSerializationByteStrmOld();
// testObj.testSerializationByteStrmNew();
@@ -181,6 +190,17 @@ public static void doTests(PerfTests testObj, METHODS method, int[] numDocs) thr
System.out.println(" ");
+ if(onlyTestBatchComp)
+ {
+ for(int i=0; i<testObj._listNum; ++i)
+ {
+ System.out.println("final statistics for ONLY batch comp time test: ---------- ");
+ System.out.println("Input size: " + testObj._numDocs[i] + " random numbers out of " + testObj._maxDoc + " numbers; ");
+ System.out.println(", avg no batch comp time: " + (double)testObj._oldTime[i]/(double)(tryTimes-1) + ", avg batch comp time: " + (double)testObj._newTime[i]/(double)(tryTimes-1));
+ }
+ return;
+ }
+
for(int i=0; i<testObj._listNum; ++i)
{
switch(method)
@@ -294,7 +314,7 @@ public void reset(int[] numDocs)
_listNum = numDocs.length;
System.arraycopy(numDocs,0,_numDocs,0, _listNum);
}
-
+
public void init(int batchSize) throws Exception
{
_batchSize = batchSize;
@@ -328,7 +348,7 @@ public void init(int batchSize) throws Exception
{
_input[i] = generateRandomDataHY(_originalInput,_maxDoc, _numDocs[i]);
//loadRandomDataSets(_input[i], _obs, _docs, _docsOld, _numDocs[i]);
- loadRandomDataSetsBatch(_input[i], _obs, _docs, _docsOld, _numDocs[i]);
+ loadRandomDataSets(_input[i], _obs, _docs, _docsOld, _numDocs[i]);
loadRandomDataSetsOldIsIntArray(_input[i], _docsIntArray);
//printList(_input[i],0, _numDocs[i]-1);
}
@@ -350,6 +370,46 @@ public void init(int batchSize) throws Exception
//printList(_expectedIntersectionResult,0,_expectedIntersectionResult.size()-1);
}
+
+ public void initAndTestCompTime(int batchSize) throws Exception
+ {
+ _batchSize = batchSize;
+
+ _obs = new ArrayList<OpenBitSet>();
+ _docs = new ArrayList<DocIdSet>();
+ _docsOld = new ArrayList<DocIdSet>();
+ _docsIntArray = new ArrayList<DocIdSet>();
+ _expectedIntersectionResult = new ArrayList<Integer>();
+
+ _originalInput = new int[_maxDoc];
+ for(int i =0; i<_maxDoc; ++i)
+ {
+ _originalInput[i] = i;
+ }
+
+ for(int i=0; i<_listNum; ++i)
+ {
+ _input[i] = generateRandomDataHY(_originalInput,_maxDoc, _numDocs[i]);
+
+ long start = System.currentTimeMillis();
+ DocSet p4d = DocSetFactory.getPForDeltaDocSetInstance();
+ for(int in:_input[i])
+ {
+ p4d.addDoc(in);
+ }
+ long end = System.currentTimeMillis();
+ _oldTime[i] += (end - start);
+
+ long startBatch = System.currentTimeMillis();
+ DocSet p4dBatch = DocSetFactory.getPForDeltaDocSetInstance();
+ p4dBatch.addDocs(_input[i], 0, _input[i].length);
+ long endBatch = System.currentTimeMillis();
+ _newTime[i] += (endBatch - startBatch);
+
+ }
+
+
+ }
public void freeMem() throws Exception
{

0 comments on commit bf13927

Please sign in to comment.