1 #include "XMLDocShredder.h"
12 static clock_t tFirstChild = 0;
13 static clock_t tNextSibling = 0;
14 static clock_t tTaggedDesc = 0;
15 static clock_t tTaggedFoll = 0;
16 static clock_t tParentNode = 0;
17 static clock_t tPrevNode = 0;
18 static clock_t tTag = 0;
19 static clock_t tMyText = 0;
20 static clock_t tPrevText = 0;
21 static clock_t tNextText = 0;
22 static clock_t tFullTraversal = 0;
23 static clock_t tJumpTraversal = 0;
25 static unsigned int cFirstChild = 0;
26 static unsigned int cNextSibling = 0;
27 static unsigned int cTaggedDesc = 0;
28 static unsigned int cTaggedFoll = 0;
29 static unsigned int cParentNode = 0;
30 static unsigned int cPrevNode = 0;
31 static unsigned int cTag = 0;
32 static unsigned int cMyText = 0;
33 static unsigned int cPrevText = 0;
34 static unsigned int cNextText = 0;
35 static unsigned int cFullTraversal = 0;
36 static unsigned int cJumpTraversal = 0;
40 static TagType target_tag = -1;
42 #define STARTTIMER() (tmp= clock())
43 #define STOPTIMER(x) do { (t##x) = (t##x) + (clock() - tmp); (c##x)= (c##x)+1; } while (0)
44 #define PRINTSTATS(x) do { \
45 std::cout.width(11); \
46 std::cout << std::left << #x; \
49 std::cout << std::right << c##x << " calls,"; \
51 std::cout << std::right << t##x << " cycles, total:"; \
53 std::cout << std::right << ((t##x) *1000.00) /CLOCKS_PER_SEC \
56 std::cout << std::right \
57 << (((t##x)* 1000.00) /CLOCKS_PER_SEC) / c##x \
62 void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){
66 const unsigned char * tagname;
69 tag = tree->Tag(node);
71 if (target_tag == -1){
72 tagname = tree->GetTagNameByRef(tag);
73 if (strcmp( (char*) tagname, (char*) targettagname) == 0)
77 res1 = tree->TaggedDesc(node,tag);
78 STOPTIMER(TaggedDesc);
81 res1 = tree->TaggedFoll(node,tag);
82 STOPTIMER(TaggedFoll);
85 id1 = tree->MyText(node);
89 id2 = tree->PrevText(node);
93 id3 = tree->NextText(node);
96 id1 = max(id1, max(id2,id3));
99 res1 = tree->ParentNode(id1);
100 STOPTIMER(ParentNode);
103 res1 = tree->PrevNode(id1);
107 res1 = tree->FirstChild(node);
108 STOPTIMER(FirstChild);
111 res2 = tree->NextSibling(node);
112 STOPTIMER(NextSibling);
113 traversal(tree,res1,targettagname);
114 traversal(tree,res2,targettagname);
120 unsigned int time_traversal(XMLTree *tree,treeNode node,unsigned int count){
124 tag = tree->Tag(node);
125 if (tag == target_tag)
127 return time_traversal(tree,tree->NextSibling(node),
128 time_traversal(tree,tree->FirstChild(node),count));
136 unsigned int time_jump(XMLTree* tree, treeNode node,unsigned int count,treeNode root){
140 tag = tree->Tag(node);
141 if (tag == target_tag)
143 return time_jump(tree,
144 tree->TaggedFollBelow(node,target_tag,root),
146 tree->TaggedDesc(node,target_tag),
160 int main(int argc, char ** argv){
161 unsigned int count1,count2;
162 unsigned char * tagname = (unsigned char *) "keyword";
165 std::cout << "Usage : " << argv[0] << " filename (without .srx)\n";
169 // The samplerate is not taken into account for loading anymore
170 XMLTree * tree = XMLTree::Load((unsigned char*) argv[1],64);
172 traversal(tree,tree->Root(),tagname);
175 count1 = time_traversal(tree,tree->Root(),0);
176 STOPTIMER(FullTraversal);
178 count2 = time_jump(tree,tree->Root(),0,tree->Root());
179 STOPTIMER(JumpTraversal);
181 PRINTSTATS(FirstChild);
182 PRINTSTATS(NextSibling);
184 PRINTSTATS(TaggedDesc);
185 PRINTSTATS(TaggedFoll);
186 PRINTSTATS(PrevText);
188 PRINTSTATS(NextText);
189 PRINTSTATS(ParentNode);
190 PRINTSTATS(PrevNode);
192 std::cout << "Full traversal found " << count1 << " " << tagname << " nodes\n";
193 PRINTSTATS(FullTraversal);
195 std::cout << "Jump traversal found " << count2 << " " << tagname << " nodes\n";
196 PRINTSTATS(JumpTraversal);