X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=timeXMLTree.cpp;h=68e75560928a1f9be8e8eed6676c6c3022d5f462;hb=52101d20031fd52639753282519b8a45e26ecb5d;hp=ed721cde76537aa0af0e4d40ec7f3088421bdd4b;hpb=a7dc14cd894ab8ecc34a3f47db0150232950e5b7;p=SXSI%2Fxpathcomp.git diff --git a/timeXMLTree.cpp b/timeXMLTree.cpp index ed721cd..68e7556 100644 --- a/timeXMLTree.cpp +++ b/timeXMLTree.cpp @@ -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; @@ -84,8 +87,8 @@ void traversal(XMLTree * tree, treeNode node,unsigned char* targettagname){ STOPTIMER(Tag); if (target_tag == -1){ tagname = tree->GetTagNameByRef(tag); - if (strcmp( (char*) tagname, (char*) targettagname) == 0) - target_tag = tag; + //if (strcmp( (char*) tagname, (char*) targettagname) == 0) + target_tag = tag; }; STARTTIMER(); res1 = tree->Parent(node); @@ -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);