1 // Test driver for text collection
13 #include "TextCollection.h"
14 using SXSI::TextCollection;
16 int main(int argc, char**argv)
20 unsigned int max_str = 0;
21 unsigned int num_str = 0;
26 string words[] = { "abcd", "abc", "mirrors", "attires", "mature",
27 "rescue", "such", "embrace", "shipping", "ae",
28 "preventions", "ab", "fe", "w" };
32 TextCollection *csa = TextCollection::InitTextCollection(64);
35 gettimeofday(&t1,NULL);
36 std::cerr << "Filling collection\n";
37 while (not(cin.eof()) && num_str < 100000 ){
38 getline(cin,str); // Read line by line.
39 if (str.compare("----------") == 0){
40 csa->InsertText((unsigned char*) buffer.c_str());
42 if (num_str % 10000 == 0){
43 gettimeofday(&t2,NULL);
44 time = ((t2.tv_sec - t1.tv_sec) * 1000000.0
45 + (t2.tv_usec - t1.tv_usec))/1000.0;
46 std::cerr << "Added " << num_str << " strings in "
48 gettimeofday(&t1,NULL);
52 if (max_str < buffer.size())
53 max_str = buffer.size();
60 std::cerr << "Calling MakeStatic()\n";
62 std::cerr << "Statistics: " << num_str << " strings, " << max_str << " = max length\n";
65 TextCollection::document_result res;
66 for (int i = 0; i < 14; i++){
67 gettimeofday(&t1,NULL);
68 is = csa->IsContains((unsigned char*) words[i].c_str());
69 gettimeofday(&t2,NULL);
70 time = ((t2.tv_sec - t1.tv_sec) * 1000000.0
71 + (t2.tv_usec - t1.tv_usec))/1000.0;
73 std::cerr << is << ", " << time << ", ";
76 gettimeofday(&t1,NULL);
77 count = csa->Count((unsigned char*) words[i].c_str());
78 gettimeofday(&t2,NULL);
79 time = ((t2.tv_sec - t1.tv_sec) * 1000000.0
80 + (t2.tv_usec - t1.tv_usec))/1000.0;
82 std::cerr << count << ", " << time << ", ";
84 gettimeofday(&t1,NULL);
85 count = csa->CountContains((unsigned char*) words[i].c_str());
86 gettimeofday(&t2,NULL);
87 time = ((t2.tv_sec - t1.tv_sec) * 1000000.0
88 + (t2.tv_usec - t1.tv_usec))/1000.0;
90 std::cerr << count << ", " << time << ", ";
93 gettimeofday(&t1,NULL);
94 res = csa->Contains((unsigned char*) words[i].c_str());
95 gettimeofday(&t2,NULL);
96 time = ((t2.tv_sec - t1.tv_sec) * 1000000.0
97 + (t2.tv_usec - t1.tv_usec))/1000.0;
99 std::cerr << time << "\n";