bug fixes, added the count queries
[SXSI/xpathcomp.git] / timeXMLTree.cpp
index aef9731..883e119 100644 (file)
@@ -9,21 +9,29 @@ using std::string;
 using std::left;
 using std::right;
 
-static clock_t tFirstChild = 0;
-static clock_t tNextSibling = 0;
-static clock_t tTaggedDesc = 0;
-static clock_t tTaggedFoll = 0;
-static clock_t tParentNode = 0;
-static clock_t tPrevNode = 0;
-static clock_t tTag = 0;
-static clock_t tMyText = 0;
-static clock_t tPrevText = 0;
-static clock_t tNextText = 0;
-static clock_t tFullTraversal = 0;
-static clock_t tJumpTraversal = 0;
+static double tFirstChild = 0;
+static double tNextSibling = 0;
+static double tParent = 0;
+static double tTaggedAncestor = 0;
+static double tTaggedChild = 0;
+static double tTaggedDesc = 0;
+static double tTaggedFoll = 0;
+static double tParentNode = 0;
+static double tPrevNode = 0;
+static double tTag = 0;
+static double tMyText = 0;
+static double tPrevText = 0;
+static double tNextText = 0;
+static double tDocIds = 0;
+
+static double tFullTraversal = 0;
+static double tJumpTraversal = 0;
 
 static unsigned int cFirstChild = 0;
 static unsigned int cNextSibling = 0;
+static unsigned int cParent = 0;
+static unsigned int cTaggedAncestor = 0;
+static unsigned int cTaggedChild = 0;
 static unsigned int cTaggedDesc = 0;
 static unsigned int cTaggedFoll = 0;
 static unsigned int cParentNode = 0;
@@ -32,39 +40,48 @@ static unsigned int cTag = 0;
 static unsigned int cMyText = 0;
 static unsigned int cPrevText = 0;
 static unsigned int cNextText = 0;
+static unsigned int cDocIds = 0;
+
 static unsigned int cFullTraversal = 0;
 static unsigned int cJumpTraversal = 0;
 
-static clock_t tmp;
+
+static struct timeval tmpv1;
+static struct timeval tmpv2;
 
 static TagType target_tag = -1;
 
-#define STARTTIMER()   (tmp= clock())
-#define STOPTIMER(x)   do {  (t##x) = (t##x) + (clock() - tmp); (c##x)= (c##x)+1;  } while (0)
+#define STARTTIMER()   (gettimeofday(&tmpv1,NULL))
+#define STOPTIMER(x)   do {                                            \
+    gettimeofday(&tmpv2,NULL);                                         \
+    (t##x) = (t##x) + ((tmpv2.tv_sec  - tmpv1.tv_sec) * 1000000.0 +    \
+                      (tmpv2.tv_usec  - tmpv1.tv_usec))/1000.0;        \
+    (c##x)= (c##x)+1;                                                  \
+  } while (0)
+
 #define PRINTSTATS(x)  do {                                            \
-    std::cout.width(11);                                               \
+    std::cout.width(15);                                               \
     std::cout << std::left << #x;                                      \
     std::cout << " : ";                                                        \
     std::cout.width(8);                                                        \
-    std::cout << std::right << c##x << " calls,";                      \
+    std::cout << std::right << c##x << " calls, ";                     \
     std::cout.width(8);                                                        \
-    std::cout << std::right << t##x << " cycles, total:";              \
-    std::cout.width(5);                                                        \
-    std::cout << std::right << ((t##x) *1000.00)  /CLOCKS_PER_SEC      \
+    std::cout << std::right << (t##x)                                  \
              << " ms, mean: ";                                         \
-    std::cout.width(5);                                                        \
+    std::cout.width(8);                                                        \
     std::cout << std::right                                            \
-             << (((t##x)* 1000.00)  /CLOCKS_PER_SEC) / c##x            \
+             << (t##x)  *1.00 / c##x                                   \
              << "\n";                                                  \
   } while (0)
 
-
 void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){
   treeNode res1,res2;
   TagType tag;
   DocID id1,id2,id3;
+  range rg;
   const unsigned char * tagname;
   if (node != NULLT){
+
     STARTTIMER();
     tag = tree->Tag(node);
     STOPTIMER(Tag);
@@ -74,12 +91,28 @@ void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){
        target_tag = tag;
     };
     STARTTIMER();
+    res1 = tree->Parent(node);
+    STOPTIMER(Parent);
+    /*
+    STARTTIMER();
+    res1 = tree->TaggedChild(node,0,tag);
+    STOPTIMER(TaggedChild);
+
+    STARTTIMER();
+    res1 = tree->TaggedAncestor(node,tag);
+    STOPTIMER(TaggedAncestor);
+    */
+    STARTTIMER();
     res1 = tree->TaggedDesc(node,tag);
     STOPTIMER(TaggedDesc);
 
     STARTTIMER();
     res1 = tree->TaggedFoll(node,tag);
     STOPTIMER(TaggedFoll);
+    
+    STARTTIMER();
+    rg = tree->DocIds(node);
+    STOPTIMER(DocIds);
 
     STARTTIMER();
     id1 = tree->MyText(node);
@@ -110,6 +143,7 @@ void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){
     STARTTIMER();
     res2 = tree->NextSibling(node);
     STOPTIMER(NextSibling);
+
     traversal(tree,res1,targettagname);
     traversal(tree,res2,targettagname);
     
@@ -117,40 +151,43 @@ void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){
   
 }
 
-unsigned int time_traversal(XMLTree *tree,treeNode node,unsigned int count){
+/* This simulates the run function of the automata */
+
+unsigned int time_traversal(XMLTree *tree,treeNode node){
   TagType tag;
   if (node != NULLT) {
     cFullTraversal++;
     tag = tree->Tag(node);
-    if (tag == target_tag)
-      count = count + 1;
-    return time_traversal(tree,tree->NextSibling(node), 
-                         time_traversal(tree,tree->FirstChild(node),count));
+    if (tag == target_tag)      
+      return 1 + 
+       time_traversal(tree,tree->FirstChild(node)) +
+       time_traversal(tree,tree->NextSibling(node)); 
+    else
+      return time_traversal(tree,tree->FirstChild(node)) +
+       time_traversal(tree,tree->NextSibling(node));
 
   }
   else 
-    return count;
+    return 0;
 }
 
-
-unsigned int time_jump(XMLTree* tree, treeNode node,unsigned int count,treeNode root){
+/* This simulates the run function of the jumping automata*/
+unsigned int time_jump(XMLTree* tree, treeNode node,treeNode root){
   TagType tag;
   if (node != NULLT) {
     cJumpTraversal++;
     tag = tree->Tag(node);
     if (tag == target_tag)
-      count = count + 1;
-    return time_jump(tree,
-                         tree->TaggedFollBelow(node,target_tag,root), 
-                         time_jump(tree,
-                                   tree->TaggedDesc(node,target_tag),
-                                   count,
-                                   node),
-                    root);
-    
+      return 1 + 
+       time_jump(tree, tree->TaggedDesc(node,target_tag),node) +
+       time_jump(tree, tree->TaggedFollBelow(node,target_tag,root),  root);
+
+    else
+      return time_jump(tree, tree->TaggedDesc(node,target_tag),node) +
+       time_jump(tree, tree->TaggedFollBelow(node,target_tag,root),  root);
   }
   else 
-    return count;
+    return 0;
 }
 
 
@@ -172,15 +209,19 @@ int main(int argc, char ** argv){
   traversal(tree,tree->Root(),tagname);
 
   STARTTIMER();
-  count1 = time_traversal(tree,tree->Root(),0);
+  count1 = time_traversal(tree,tree->Root());
   STOPTIMER(FullTraversal);
 
-  count2 = time_jump(tree,tree->Root(),0,tree->Root());
+  count2 = time_jump(tree,tree->Root(),tree->Root());
   STOPTIMER(JumpTraversal);
-  
+
+  PRINTSTATS(Tag);
   PRINTSTATS(FirstChild);
   PRINTSTATS(NextSibling);
-  PRINTSTATS(Tag);
+  PRINTSTATS(Parent);
+  PRINTSTATS(TaggedAncestor);
+  PRINTSTATS(TaggedChild);
+  PRINTSTATS(DocIds);
   PRINTSTATS(TaggedDesc);
   PRINTSTATS(TaggedFoll);
   PRINTSTATS(PrevText);