1 // Test driver for text collection
5 #include "HeapProfiler.h"
11 #include "TextCollection.h"
12 using SXSI::TextCollection;
14 void printDocumentResult(TextCollection::document_result dr)
16 TextCollection::document_result::iterator it;
17 printf("document result:");
18 for (it = dr.begin(); it != dr.end(); ++it)
24 void printFullResult(TextCollection::full_result fr)
26 TextCollection::full_result::iterator it;
27 printf("full result:");
28 for (it = fr.begin(); it != fr.end(); ++it)
29 printf(" (%i, %lu)", (*it).first, (*it).second);
40 int heap_base = HeapProfiler::GetHeapConsumption (5); // Avoid small samplerates ;)
41 std::cerr << "Initial heap usage : " << heap_base << "\n";
42 TextCollection *csa = TextCollection::InitTextCollection();
43 heap_base = HeapProfiler::GetHeapConsumption ();
44 std::cerr << "Heap usage after InitTextCollection : " << heap_base << "\n";
47 while (not(cin.eof())){
48 getline(cin,str); // Read line by line.
49 // cin >> str; // Read word by word.
50 data = (uchar *) str.c_str();
51 csa->InsertText(data);
56 std::cerr << "Inserted : " << i << " strings\n";
57 std::cerr << "Number of bytes inserted : " << j << "b \n";
58 std::cerr << "Heap usage used for strings: " << HeapProfiler::GetHeapConsumption() - heap_base
60 std::cerr << "Ratio is : " << (float) (HeapProfiler::GetHeapConsumption() - heap_base) / ((float) j) <<"\n";
66 /* the whole file as one string:
67 uchar *temp = Tools::GetFileContents("data.txt", 0);
68 csa->InsertText(temp);
71 std::cerr << "Creating new text collection with " << i << " strings (total " << j/1024 << " kb)\n";
72 std::cerr << "Before MakeStatic() [press enter]\n";
74 // This will print the maximum mem usage during construction time:
75 std::cerr << "max heap usage: " << HeapProfiler::GetMaxHeapConsumption()/(1024*1024) << " Mbytes" << std::endl;
77 std::cerr << "After MakeStatic() [press enter]\n";
78 // This will print the maximum mem usage during MakeStatic():
79 std::cerr << "max heap usage: " << HeapProfiler::GetMaxHeapConsumption()/(1024*1024) << " Mbytes" << std::endl;
81 std::cerr << "heap usage: " << HeapProfiler::GetHeapConsumption()/(1024*1024) << " Mbytes" << std::endl;
83 std::cerr << "After Delete [press enter]\n";
84 std::cerr << "heap usage: " << HeapProfiler::GetHeapConsumption()/(1024*1024) << " Mbytes" << std::endl;