X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=testTextCollection.cpp;h=a19d2b20fc2dbddc539d1d1883f37b176469fb81;hb=refs%2Fheads%2Fmaster;hp=d005b8f489e607b26db23ebdd8351f3688ae1d14;hpb=7d27a4450ed429e3b63e9d3ba7217a28cbbf9a31;p=SXSI%2FTextCollection.git diff --git a/testTextCollection.cpp b/testTextCollection.cpp index d005b8f..a19d2b2 100644 --- a/testTextCollection.cpp +++ b/testTextCollection.cpp @@ -1,9 +1,15 @@ // Test driver for text collection #include +#include +#include using std::cout; using std::endl; +using std::cin; +using std::string; -#include "TextCollection.h" +#include "TextCollectionBuilder.h" +#include "HeapProfiler.h" +using SXSI::TextCollectionBuilder; using SXSI::TextCollection; void printDocumentResult(TextCollection::document_result dr) @@ -28,42 +34,75 @@ void printFullResult(TextCollection::full_result fr) int main() { - uchar *text = (uchar*) "acabab"; - TextCollection *csa = TextCollection::InitTextCollection(1); - csa->InsertText(text); - text = (uchar*) "abaca"; - csa->InsertText(text); - text = (uchar*) "abacb"; - csa->InsertText(text); + std::string kbd; + string str; + uchar* data; + int i = 0 ,j = 0; + int heap_base = HeapProfiler::GetHeapConsumption(); + std::cerr << "Initial heap usage : " << heap_base << "\n"; + TextCollectionBuilder *tcb = TextCollectionBuilder::create(5); + heap_base = HeapProfiler::GetHeapConsumption (); + std::cerr << "Heap usage after InitTextCollection : " << heap_base << "\n"; + Tools::StartTimer(); - csa->MakeStatic(); + while (not(cin.eof())){ + getline(cin,str); // Read line by line. +// cin >> str; // Read word by word. + data = (uchar *) str.c_str(); + if (str.size() == 0) + continue; + + tcb->InsertText(data); + i++; + j+= str.size(); + str.clear(); + if ( i % 100000 == 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"; + + }; - text = csa->GetText(0); - cout << "Text 0: \"" << text << "\"" << endl; - delete [] text; - text = csa->GetText(1); - cout << "Text 1: \"" << text << "\"" << endl; - delete [] text; - text = csa->GetText(2); - cout << "Text 2: \"" << text << "\"" << endl; - delete [] text; - - text = csa->GetText(2, 2, 4); - cout << "Substring of Text 3: \"" << text << "\"" << endl; - delete [] text; - - printf("n:o contains: %u\n", csa->CountContains((uchar *)"ac")); - printf("n:o suffix: %u\n", csa->CountSuffix((uchar *)"b")); - printf("n:o equal: %u\n", csa->CountEqual((uchar *)"acabab")); - printf("is equal: %u\n", csa->IsEqual((uchar *)"abacb")); - - TextCollection::document_result dr; - dr = csa->Contains((uchar*)"ab"); - printDocumentResult(dr); + }; +/**/ + //the whole file as 20 strings: + /* uchar *temp = Tools::GetFileContents("data/english.100MB", 0); + ulong n = strlen((char *)temp); + std::cout << "n = " << n << std::endl; + ulong offset = n/40; + uchar *it = temp; + for (i = 0; i < 5; ++i) + { + it[offset] = '\0'; + tcb->InsertText(it); + std::cout << "inserted " << strlen((char *)it) << " bytes." << std::endl; + it += offset +1; + } + it -= offset+1; - TextCollection::full_result fr; - fr = csa->FullContains((uchar *)"ab"); - printFullResult(fr); + if (it > temp + n) + std::cout << "over bounds" << std::endl; + delete [] temp;*/ + - delete csa; + std::cerr << "Creating new text collection with " << i << " strings (total " << j/1024 << " kb)\n"; + std::cerr << "max heap usage: " << HeapProfiler::GetMaxHeapConsumption()/(1024*1024) << " Mbytes" << std::endl; + HeapProfiler::ResetMaxHeapConsumption(); + std::cerr << "Before MakeStatic() [press enter]\n"; + //std::cin >> kbd; + // This will print the maximum mem usage during construction time: + TextCollection* tc = tcb->InitTextCollection();//SXSI::TextStorage::TYPE_LZ_INDEX); + delete tcb; tcb = 0; + 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 tc; + std::cerr << "After Delete [press enter]\n"; + std::cerr << "heap usage: " << HeapProfiler::GetHeapConsumption() << " bytes" << std::endl; + //std::cin >> kbd; + return 0; }