1 // Test driver for text collection
12 static struct timeval t1;
13 static struct timeval t2;
15 #define STARTTIMER() (gettimeofday(&t1,NULL))
16 #define STOPTIMER() (gettimeofday(&t2,NULL))
17 #define GETTIME() (((t2.tv_sec - t1.tv_sec) * 1000000.0 + (t2.tv_usec - t1.tv_usec))/1000.0)
21 #include "TextCollectionBuilder.h"
22 using SXSI::TextCollection;
23 using SXSI::TextCollectionBuilder;
25 int main(int argc, char**argv)
29 unsigned int max_str = 0;
30 unsigned int num_str = 0;
33 string words[] = { "abcd", "abc", "mirrors", "attires", "mature",
34 "rescue", "such", "embrace", "shipping", "ae",
35 "preventions", "ab", "fe", "w" };
39 TextCollectionBuilder *tcb = new TextCollectionBuilder(64);
43 std::cerr << "Filling collection\n";
44 // read only 100000 strings
45 while (not(cin.eof()) && num_str < 100000 ){
46 getline(cin,str); // Read line by line.
47 if (str.compare("----------") == 0){
48 tcb->InsertText((unsigned char*) buffer.c_str());
50 if (num_str % 10000 == 0){
53 std::cerr << "Added " << num_str << " strings in "
59 if (max_str < buffer.size())
60 max_str = buffer.size();
67 std::cerr << "Calling MakeStatic()\n";
69 TextCollection *tc = tcb->InitTextCollection();
71 std::cerr << "Statistics: " << num_str << " strings, " << max_str << " = max length\n";
74 TextCollection::document_result res;
75 for (unsigned int i = 0; i < (sizeof(words)/sizeof(char*)) ; i++){
78 is = tc->IsContains((unsigned char*) words[i].c_str());
82 std::cerr << is << ", " << time << ", ";
86 count = tc->Count((unsigned char*) words[i].c_str());
90 std::cerr << count << ", " << time << ", ";
94 count = tc->CountContains((unsigned char*) words[i].c_str());
98 std::cerr << count << ", " << time << ", ";
102 res = tc->Contains((unsigned char*) words[i].c_str());
106 std::cerr << time << "\n";