From 5cb50b1ff34e22ef1278271c0770924ed075c78f Mon Sep 17 00:00:00 2001 From: kim Date: Wed, 7 Jan 2009 03:53:22 +0000 Subject: [PATCH] Test case for memory consumption with the TextCollection. git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/TextCollection@28 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- testTextCollection.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/testTextCollection.cpp b/testTextCollection.cpp index dd37ff1..3add025 100644 --- a/testTextCollection.cpp +++ b/testTextCollection.cpp @@ -1,9 +1,12 @@ // Test driver for text collection #include #include +#include #include "HeapProfiler.h" using std::cout; using std::endl; +using std::cin; +using std::string; #include "TextCollection.h" using SXSI::TextCollection; @@ -31,12 +34,35 @@ 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); + 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); + 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"; + + }; + }; + + 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; -- 2.17.1