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> |
|
5 |
||
6 |
#include "tools.h" |
|
7 |
||
8 |
#if LIBXML_VERSION > 20600
|
|
9 |
#define _SAX2_BENCHMARK
|
|
10 |
#endif
|
|
11 |
||
9
by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers |
12 |
|
1
by Suren A. Chilingaryan
Initial import |
13 |
void startElement_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) { |
14 |
}
|
|
15 |
void endElement_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) { |
|
16 |
}
|
|
17 |
void characters_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) { |
|
9
by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers |
18 |
}
|
19 |
||
20 |
double res_total; |
|
21 |
double res_attr[MAX_LEVELS+1]; |
|
22 |
double res_sum[MAX_LEVELS+1]; |
|
23 |
int res_count[MAX_LEVELS+1]; |
|
24 |
int level = 0; |
|
25 |
||
26 |
void startDocument_c(void * ctx) { |
|
27 |
level = 0; |
|
28 |
res_total = 0; |
|
29 |
res_count[0] = 0; |
|
30 |
}
|
|
31 |
||
32 |
void startElement_c(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) { |
|
33 |
int i; |
|
34 |
double res = 0; |
|
35 |
||
36 |
if (atts) { |
|
37 |
for (i = 0; atts[i]; i++) { |
|
38 |
res = get_value(atts[i]); |
|
39 |
if (res) break; |
|
40 |
}
|
|
41 |
}
|
|
42 |
||
43 |
// printf("%i %lf\n", level, res);
|
|
44 |
res_attr[level] = res; |
|
45 |
if (++level == MAX_LEVELS) { |
|
46 |
printf("XML structure is too deep, only %i levels are supported\n", MAX_LEVELS); |
|
47 |
exit(1); |
|
48 |
}
|
|
49 |
res_count[level]=0; |
|
50 |
||
51 |
return; |
|
52 |
}
|
|
53 |
||
54 |
void endElement_c(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) { |
|
55 |
// printf("end: %i %s: %i %lf %i %lf\n", level, name, res_count[level-1], res_sum[level-1], res_count[level], res_sum[level]);
|
|
56 |
if (res_count[level] > 3) { |
|
57 |
res_total += res_sum[level]; |
|
58 |
}
|
|
59 |
||
60 |
--level; |
|
61 |
if (res_count[level]) { |
|
62 |
res_sum[level]+=res_attr[level]; |
|
63 |
} else { |
|
64 |
res_sum[level]=res_attr[level]; |
|
65 |
}
|
|
66 |
++res_count[level]; |
|
67 |
||
68 |
return; |
|
69 |
}
|
|
70 |
||
71 |
void characters_c(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) { |
|
72 |
if (ch) { |
|
73 |
double res = get_value_0(ch,len); |
|
74 |
if (res) res_attr[level-1] = res; |
|
75 |
}
|
|
1
by Suren A. Chilingaryan
Initial import |
76 |
return; |
77 |
}
|
|
78 |
||
79 |
||
80 |
xmlSAXHandler handler = { |
|
81 |
NULL, /* internalSubset */ |
|
82 |
NULL, /* isStandalone */ |
|
83 |
NULL, /* hasInternalSubset */ |
|
84 |
NULL, /* hasExternalSubset */ |
|
85 |
NULL, /* resolveEntity */ |
|
86 |
NULL, /* getEntity */ |
|
87 |
NULL, /* entityDecl */ |
|
88 |
NULL, /* notationDecl */ |
|
89 |
NULL, /* attributeDecl */ |
|
90 |
NULL, /* elementDecl */ |
|
91 |
NULL, /* unparsedEntityDecl */ |
|
92 |
NULL, /* setDocumentLocator */ |
|
93 |
NULL, /* startDocument */ |
|
94 |
NULL, /* endDocument */ |
|
95 |
startElement_, /* startElement */ |
|
96 |
endElement_, /* endElement */ |
|
97 |
NULL, /* reference */ |
|
98 |
characters_, /* characters */ |
|
99 |
NULL, /* ignorableWhitespace */ |
|
100 |
NULL, /* processingInstruction */ |
|
101 |
NULL, /* comment */ |
|
102 |
NULL, /* xmlParserWarning */ |
|
103 |
NULL, /* xmlParserError */ |
|
104 |
NULL, /* xmlParserError */ |
|
105 |
NULL, /* getParameterEntity */ |
|
106 |
NULL, /* cdataBlock; */ |
|
107 |
NULL, /* externalSubset; */ |
|
108 |
#ifndef _SAX2_BENCHMARK
|
|
109 |
1
|
|
110 |
#else
|
|
111 |
XML_SAX2_MAGIC, /* XML_SAX1_MAGIC, XML_SAX2_MAGIC */ |
|
112 |
NULL, |
|
113 |
NULL, /* startElementNs */ |
|
114 |
NULL, /* endElementNs */ |
|
115 |
NULL /* xmlStructuredErrorFunc */ |
|
116 |
#endif /* _SAX2_BENCHMARK */ |
|
117 |
};
|
|
118 |
||
9
by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers |
119 |
xmlSAXHandler count_handler = { |
120 |
NULL, /* internalSubset */ |
|
121 |
NULL, /* isStandalone */ |
|
122 |
NULL, /* hasInternalSubset */ |
|
123 |
NULL, /* hasExternalSubset */ |
|
124 |
NULL, /* resolveEntity */ |
|
125 |
NULL, /* getEntity */ |
|
126 |
NULL, /* entityDecl */ |
|
127 |
NULL, /* notationDecl */ |
|
128 |
NULL, /* attributeDecl */ |
|
129 |
NULL, /* elementDecl */ |
|
130 |
NULL, /* unparsedEntityDecl */ |
|
131 |
NULL, /* setDocumentLocator */ |
|
132 |
startDocument_c, /* startDocument */ |
|
133 |
NULL, /* endDocument */ |
|
134 |
startElement_c, /* startElement */ |
|
135 |
endElement_c, /* endElement */ |
|
136 |
NULL, /* reference */ |
|
137 |
characters_c, /* characters */ |
|
138 |
NULL, /* ignorableWhitespace */ |
|
139 |
NULL, /* processingInstruction */ |
|
140 |
NULL, /* comment */ |
|
141 |
NULL, /* xmlParserWarning */ |
|
142 |
NULL, /* xmlParserError */ |
|
143 |
NULL, /* xmlParserError */ |
|
144 |
NULL, /* getParameterEntity */ |
|
145 |
NULL, /* cdataBlock; */ |
|
146 |
NULL, /* externalSubset; */ |
|
147 |
#ifndef _SAX2_BENCHMARK
|
|
148 |
1
|
|
149 |
#else
|
|
150 |
XML_SAX2_MAGIC, /* XML_SAX1_MAGIC, XML_SAX2_MAGIC */ |
|
151 |
NULL, |
|
152 |
NULL, /* startElementNs */ |
|
153 |
NULL, /* endElementNs */ |
|
154 |
NULL /* xmlStructuredErrorFunc */ |
|
155 |
#endif /* _SAX2_BENCHMARK */ |
|
156 |
};
|
|
157 |
||
158 |
||
1
by Suren A. Chilingaryan
Initial import |
159 |
void initXML(struct TestData *td) { |
160 |
}
|
|
161 |
||
162 |
void releaseXML(struct TestData *td) { |
|
163 |
xmlCleanupParser(); |
|
164 |
}
|
|
165 |
||
166 |
void parseXML(struct TestData *td, unsigned long iter) { |
|
9
by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers |
167 |
if (walk_tree) { |
168 |
xmlSAXUserParseMemory(&count_handler,NULL,td->xml,td->xmllen); |
|
169 |
// printf("Sum: %lf\n", res_total);
|
|
170 |
} else { |
|
171 |
xmlSAXUserParseMemory(&handler,NULL,td->xml,td->xmllen); |
|
172 |
}
|
|
1
by Suren A. Chilingaryan
Initial import |
173 |
}
|
174 |
||
175 |
int main(int argc, char *argv[]) { |
|
176 |
return Test(argc,argv); |
|
177 |
}
|