1 #include "XMLDocShredder.h"
12 static clock_t tFirstChild = 0;
13 static clock_t tNextSibling = 0;
14 static clock_t tParent = 0;
15 static clock_t tTaggedAncestor = 0;
16 static clock_t tTaggedChild = 0;
17 static clock_t tTaggedDesc = 0;
18 static clock_t tTaggedFoll = 0;
19 static clock_t tParentNode = 0;
20 static clock_t tPrevNode = 0;
21 static clock_t tTag = 0;
22 static clock_t tMyText = 0;
23 static clock_t tPrevText = 0;
24 static clock_t tNextText = 0;
25 static clock_t tDocIds = 0;
27 static clock_t tFullTraversal = 0;
28 static clock_t tJumpTraversal = 0;
30 static unsigned int cFirstChild = 0;
31 static unsigned int cNextSibling = 0;
32 static unsigned int cParent = 0;
33 static unsigned int cTaggedAncestor = 0;
34 static unsigned int cTaggedChild = 0;
35 static unsigned int cTaggedDesc = 0;
36 static unsigned int cTaggedFoll = 0;
37 static unsigned int cParentNode = 0;
38 static unsigned int cPrevNode = 0;
39 static unsigned int cTag = 0;
40 static unsigned int cMyText = 0;
41 static unsigned int cPrevText = 0;
42 static unsigned int cNextText = 0;
43 static unsigned int cDocIds = 0;
45 static unsigned int cFullTraversal = 0;
46 static unsigned int cJumpTraversal = 0;
52 static TagType target_tag = -1;
54 #define STARTTIMER() (tmp= clock())
55 #define STOPTIMER(x) do { (t##x) = (t##x) + (clock() - tmp); (c##x)= (c##x)+1; } while (0)
56 #define PRINTSTATS(x) do { \
57 std::cout.width(15); \
58 std::cout << std::left << #x; \
61 std::cout << std::right << c##x << " calls,"; \
63 std::cout << std::right << t##x << " cycles, total:"; \
65 std::cout << std::right << ((t##x) *1000.00) /CLOCKS_PER_SEC \
68 std::cout << std::right \
69 << (((t##x)* 1000.00) /CLOCKS_PER_SEC) / c##x \
74 void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){
79 const unsigned char * tagname;
83 tag = tree->Tag(node);
85 if (target_tag == -1){
86 tagname = tree->GetTagNameByRef(tag);
87 if (strcmp( (char*) tagname, (char*) targettagname) == 0)
91 res1 = tree->Parent(node);
95 res1 = tree->TaggedChild(node,0,tag);
96 STOPTIMER(TaggedChild);
99 res1 = tree->TaggedAncestor(node,tag);
100 STOPTIMER(TaggedAncestor);
103 res1 = tree->TaggedDesc(node,tag);
104 STOPTIMER(TaggedDesc);
107 res1 = tree->TaggedFoll(node,tag);
108 STOPTIMER(TaggedFoll);
111 rg = tree->DocIds(node);
115 id1 = tree->MyText(node);
119 id2 = tree->PrevText(node);
123 id3 = tree->NextText(node);
126 id1 = max(id1, max(id2,id3));
129 res1 = tree->ParentNode(id1);
130 STOPTIMER(ParentNode);
133 res1 = tree->PrevNode(id1);
137 res1 = tree->FirstChild(node);
138 STOPTIMER(FirstChild);
141 res2 = tree->NextSibling(node);
142 STOPTIMER(NextSibling);
144 traversal(tree,res1,targettagname);
145 traversal(tree,res2,targettagname);
151 /* This simulates the run function of the automata */
153 unsigned int time_traversal(XMLTree *tree,treeNode node){
157 tag = tree->Tag(node);
158 if (tag == target_tag)
160 time_traversal(tree,tree->FirstChild(node)) +
161 time_traversal(tree,tree->NextSibling(node));
163 return time_traversal(tree,tree->FirstChild(node)) +
164 time_traversal(tree,tree->NextSibling(node));
171 /* This simulates the run function of the jumping automata*/
172 unsigned int time_jump(XMLTree* tree, treeNode node,treeNode root){
176 tag = tree->Tag(node);
177 if (tag == target_tag)
180 time_jump(tree, tree->TaggedDesc(node,target_tag),node) +
181 time_jump(tree, tree->TaggedFollBelow(node,target_tag,root), root);
184 return time_jump(tree, tree->TaggedDesc(node,target_tag),node) +
185 time_jump(tree, tree->TaggedFollBelow(node,target_tag,root), root);
195 int main(int argc, char ** argv){
196 unsigned int count1,count2;
197 unsigned char * tagname = (unsigned char *) "keyword";
200 std::cout << "Usage : " << argv[0] << " filename (without .srx)\n";
204 // The samplerate is not taken into account for loading anymore
205 XMLTree * tree = XMLTree::Load((unsigned char*) argv[1],64);
207 traversal(tree,tree->Root(),tagname);
210 count1 = time_traversal(tree,tree->Root());
211 STOPTIMER(FullTraversal);
213 count2 = time_jump(tree,tree->Root(),tree->Root());
214 STOPTIMER(JumpTraversal);
217 PRINTSTATS(FirstChild);
218 PRINTSTATS(NextSibling);
220 PRINTSTATS(TaggedAncestor);
221 PRINTSTATS(TaggedChild);
223 PRINTSTATS(TaggedDesc);
224 PRINTSTATS(TaggedFoll);
225 PRINTSTATS(PrevText);
227 PRINTSTATS(NextText);
228 PRINTSTATS(ParentNode);
229 PRINTSTATS(PrevNode);
231 std::cout << "Full traversal found " << count1 << " " << tagname << " nodes\n";
232 PRINTSTATS(FullTraversal);
234 std::cout << "Jump traversal found " << count2 << " " << tagname << " nodes\n";
235 PRINTSTATS(JumpTraversal);