bzr branch
http://darksoft.org/webbzr/xmlbench/trunk
1
by Suren A. Chilingaryan
Initial import |
1 |
#include <stdio.h> |
2 |
#include <sys/time.h> |
|
3 |
#include <libxml/xmlmemory.h> |
|
4 |
#include <libxml/parser.h> |
|
14
by Suren A. Chilingaryan
XPath expression optimizations, various fixes |
5 |
#include <libxml/xpath.h> |
1
by Suren A. Chilingaryan
Initial import |
6 |
|
7 |
#if LIBXML_VERSION > 20600
|
|
8 |
#define READ_MEMORY
|
|
9 |
//xmlParserCtxtPtr ctxt = NULL;
|
|
10 |
#endif
|
|
11 |
||
12 |
#ifdef READ_MEMORY
|
|
13 |
#define DTD_VALIDATION_SUPPORTED
|
|
14 |
#endif
|
|
15 |
||
16 |
#include "tools.h" |
|
17 |
||
18 |
||
9
by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers |
19 |
inline double walker_process_node(xmlNode *cur_node) { |
20 |
double res; |
|
21 |
xmlChar *value; |
|
22 |
xmlAttr *cur_attr; |
|
23 |
||
24 |
if ((cur_node->children)&&(cur_node->children->type == XML_TEXT_NODE)&&(cur_node->children->content)) { |
|
25 |
// puts(cur_node->children->content);
|
|
26 |
||
27 |
res = get_value(cur_node->children->content); |
|
28 |
if (res) return res; |
|
29 |
}
|
|
30 |
||
31 |
for (cur_attr = cur_node->properties; cur_attr; cur_attr = cur_attr->next) { |
|
32 |
// value = xmlGetProp(cur_node, cur_attr->name);
|
|
33 |
value = (char*)cur_attr->children->content; |
|
34 |
if (value) { |
|
35 |
res = get_value(value); |
|
36 |
// xmlFree(value);
|
|
37 |
if (res) return res; |
|
38 |
}
|
|
39 |
}
|
|
40 |
||
41 |
return 0; |
|
42 |
}
|
|
43 |
||
44 |
inline double xpath_walker(xmlNodeSetPtr nodes) { |
|
45 |
int i; |
|
46 |
double res = 0; |
|
47 |
int size = (nodes) ? nodes->nodeNr : 0; |
|
48 |
||
49 |
for(i = 0; i < size; ++i) { |
|
50 |
res += walker_process_node(nodes->nodeTab[i]); |
|
51 |
}
|
|
52 |
||
53 |
return res; |
|
54 |
}
|
|
14
by Suren A. Chilingaryan
XPath expression optimizations, various fixes |
55 |
|
9
by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers |
56 |
double walker(xmlNode *node) { |
57 |
int i = 0; |
|
58 |
double res = 0; |
|
59 |
xmlNode *cur_node; |
|
60 |
||
61 |
for (cur_node = node; cur_node; cur_node = cur_node->next) { |
|
62 |
if((cur_node->type == XML_ELEMENT_NODE)&&(++i>3)) break; |
|
63 |
}
|
|
64 |
||
65 |
if (i<=3) i = 0; |
|
66 |
||
67 |
for (cur_node = node; cur_node; cur_node = cur_node->next) { |
|
68 |
if (cur_node->type == XML_ELEMENT_NODE) { |
|
69 |
if (i) { |
|
70 |
res += walker_process_node(cur_node); |
|
71 |
}
|
|
72 |
if (cur_node->children) { |
|
73 |
res+=walker(cur_node->children); |
|
74 |
}
|
|
75 |
}
|
|
76 |
}
|
|
77 |
return res; |
|
78 |
}
|
|
79 |
||
1
by Suren A. Chilingaryan
Initial import |
80 |
|
81 |
void initXML(struct TestData *td) { |
|
82 |
xmlInitParser(); |
|
83 |
#ifdef READ_MEMORY
|
|
84 |
/* ctxt = xmlNewParserCtxt();
|
|
85 |
if (!ctxt) {
|
|
86 |
fprintf(stderr, "Can't create parser context!\n");
|
|
87 |
exit(0);
|
|
88 |
}*/
|
|
89 |
#endif
|
|
90 |
}
|
|
91 |
||
92 |
void releaseXML(struct TestData *td) { |
|
93 |
#ifdef READ_MEMORY
|
|
94 |
// if (ctxt) xmlFreeParserCtxt(ctxt);
|
|
95 |
#endif
|
|
96 |
xmlCleanupParser(); |
|
97 |
}
|
|
98 |
||
99 |
void parseXML(struct TestData *td, unsigned long iter) { |
|
100 |
int err; |
|
101 |
xmlDocPtr doc; |
|
102 |
#ifdef READ_MEMORY
|
|
103 |
#ifdef DTD_VALIDATION
|
|
104 |
doc=xmlReadMemory(td->xml,td->xmllen,"xml",NULL,XML_PARSE_DTDVALID); |
|
105 |
#else
|
|
106 |
doc=xmlReadMemory(td->xml,td->xmllen,"xml",NULL,0); |
|
107 |
#endif
|
|
108 |
/* doc=xmlCtxtReadMemory(ctxt,td->xml,td->xmllen,"xml",NULL,XML_PARSE_DTDVALID);
|
|
109 |
printf("%u\n",ctxt->valid); */
|
|
110 |
||
111 |
||
112 |
#else
|
|
113 |
doc=xmlParseMemory(td->xml,td->xmllen); |
|
114 |
#endif
|
|
115 |
if (!doc) { |
|
116 |
printf("Error parsing document!\n"); |
|
117 |
exit(0); |
|
118 |
}
|
|
9
by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers |
119 |
|
120 |
||
121 |
if (walk_tree) { |
|
122 |
double res; |
|
14
by Suren A. Chilingaryan
XPath expression optimizations, various fixes |
123 |
|
124 |
if (force_xpath) { |
|
125 |
xmlXPathContextPtr xpathCtx; |
|
126 |
xmlXPathObjectPtr xpathObj; |
|
127 |
||
128 |
xpathCtx = xmlXPathNewContext(doc); |
|
129 |
xpathObj = xmlXPathEvalExpression(walk_xpath, xpathCtx); |
|
130 |
if (xpathObj) { |
|
131 |
res = xpath_walker(xpathObj->nodesetval); |
|
132 |
xmlXPathFreeObject(xpathObj); |
|
133 |
xmlXPathFreeContext(xpathCtx); |
|
134 |
}
|
|
135 |
} else { |
|
136 |
res = walker(xmlDocGetRootElement(doc)); |
|
9
by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers |
137 |
}
|
11
by Suren A. Chilingaryan
DOM walking for all Libxml bindings: ruby, python, perl, php, lisp |
138 |
// printf("Sum: %lf\n", res);
|
9
by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers |
139 |
}
|
140 |
||
1
by Suren A. Chilingaryan
Initial import |
141 |
xmlFreeDoc(doc); |
142 |
||
143 |
}
|
|
144 |
||
145 |
int main(int argc, char *argv[]) { |
|
146 |
return Test(argc,argv); |
|
147 |
}
|