Changed clock() to gettimeofday()
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Wed, 11 Mar 2009 04:03:07 +0000 (04:03 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Wed, 11 Mar 2009 04:03:07 +0000 (04:03 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/xpathcomp@245 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

timeXMLTree.cpp

index ed721cd..883e119 100644 (file)
@@ -9,23 +9,23 @@ using std::string;
 using std::left;
 using std::right;
 
-static clock_t tFirstChild = 0;
-static clock_t tNextSibling = 0;
-static clock_t tParent = 0;
-static clock_t tTaggedAncestor = 0;
-static clock_t tTaggedChild = 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 tDocIds = 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;
@@ -46,31 +46,34 @@ 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(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;
@@ -175,7 +178,6 @@ unsigned int time_jump(XMLTree* tree, treeNode node,treeNode root){
     cJumpTraversal++;
     tag = tree->Tag(node);
     if (tag == target_tag)
-
       return 1 + 
        time_jump(tree, tree->TaggedDesc(node,target_tag),node) +
        time_jump(tree, tree->TaggedFollBelow(node,target_tag,root),  root);