Skip to content

Commit

Permalink
add a test for testing the comp time of batched addDocs()
Browse files Browse the repository at this point in the history
  • Loading branch information
hyan committed Dec 1, 2010
1 parent f3099c2 commit bf13927
Showing 1 changed file with 80 additions and 20 deletions.
100 changes: 80 additions & 20 deletions test/com/kamikaze/test/perf/PForDeltaPerfTest.java
Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
{
Expand Down

0 comments on commit bf13927

Please sign in to comment.