X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=testTextCollection.cpp;h=59b6b43c11f2d64ef305605e0ecdf67c2b3fb912;hb=663cd2f6cc5e3796d001e8c527de0aea8c8bbf68;hp=dd37ff11ca02e3485cc1426c7aa503284a99c048;hpb=eb04a05de55af8957aea1353d21b5e5b98bd1006;p=SXSI%2FTextCollection.git diff --git a/testTextCollection.cpp b/testTextCollection.cpp index dd37ff1..59b6b43 100644 --- a/testTextCollection.cpp +++ b/testTextCollection.cpp @@ -1,11 +1,14 @@ // Test driver for text collection #include #include -#include "HeapProfiler.h" +#include using std::cout; using std::endl; +using std::cin; +using std::string; #include "TextCollection.h" +#include "HeapProfiler.h" using SXSI::TextCollection; void printDocumentResult(TextCollection::document_result dr) @@ -31,17 +34,49 @@ void printFullResult(TextCollection::full_result fr) int main() { std::string kbd; - uchar * str = (uchar*) ""; + string str; + uchar* data; + int i = 0 ,j = 0; + int heap_base = HeapProfiler::GetHeapConsumption(); + std::cerr << "Initial heap usage : " << heap_base << "\n"; + TextCollection *csa = TextCollection::InitTextCollection(5); // Avoid small samplerates ;) + heap_base = HeapProfiler::GetHeapConsumption (); + std::cerr << "Heap usage after InitTextCollection : " << heap_base << "\n"; + - TextCollection *csa = TextCollection::InitTextCollection(64); - for(int i = 0; i<1000000; i++){ - csa->InsertText(str); - }; + while (not(cin.eof())){ + getline(cin,str); // Read line by line. +// cin >> str; // Read word by word. + data = (uchar *) str.c_str(); + csa->InsertText(data); + i++; + j+= str.size(); + str.clear(); + if ( i % 1000 == 0) { + std::cerr << "Inserted : " << i << " strings\n"; + std::cerr << "Number of bytes inserted : " << j << "b \n"; + std::cerr << "Heap usage used for strings: " << HeapProfiler::GetHeapConsumption() - heap_base + << "bytes\n"; + std::cerr << "Ratio is : " << (float) (HeapProfiler::GetHeapConsumption() - heap_base) / ((float) j) <<"\n"; + + }; + + }; + +/* the whole file as one string: + uchar *temp = Tools::GetFileContents("data.txt", 0); + csa->InsertText(temp); + delete [] temp;*/ + + std::cerr << "Creating new text collection with " << i << " strings (total " << j/1024 << " kb)\n"; std::cerr << "Before MakeStatic() [press enter]\n"; std::cin >> kbd; - std::cerr << "heap usage: " << HeapProfiler::GetHeapConsumption()/(1024*1024) << " Mbytes" << std::endl; + // This will print the maximum mem usage during construction time: + std::cerr << "max heap usage: " << HeapProfiler::GetMaxHeapConsumption()/(1024*1024) << " Mbytes" << std::endl; csa->MakeStatic(); std::cerr << "After MakeStatic() [press enter]\n"; + // This will print the maximum mem usage during MakeStatic(): + std::cerr << "max heap usage: " << HeapProfiler::GetMaxHeapConsumption()/(1024*1024) << " Mbytes" << std::endl; std::cin >> kbd; std::cerr << "heap usage: " << HeapProfiler::GetHeapConsumption()/(1024*1024) << " Mbytes" << std::endl; delete csa;