9
9
#define _SAX2_BENCHMARK
12
13
void startElement_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) {
16
15
void endElement_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) {
19
17
void characters_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) {
21
double res_attr[MAX_LEVELS+1];
22
double res_sum[MAX_LEVELS+1];
23
int res_count[MAX_LEVELS+1];
26
void startDocument_c(void * ctx) {
32
void startElement_c(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) {
37
for (i = 0; atts[i]; i++) {
38
res = get_value(atts[i]);
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);
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];
61
if (res_count[level]) {
62
res_sum[level]+=res_attr[level];
64
res_sum[level]=res_attr[level];
71
void characters_c(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) {
73
double res = get_value_0(ch,len);
74
if (res) res_attr[level-1] = res;
60
116
#endif /* _SAX2_BENCHMARK */
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 */
141
NULL, /* xmlParserWarning */
142
NULL, /* xmlParserError */
143
NULL, /* xmlParserError */
144
NULL, /* getParameterEntity */
145
NULL, /* cdataBlock; */
146
NULL, /* externalSubset; */
147
#ifndef _SAX2_BENCHMARK
150
XML_SAX2_MAGIC, /* XML_SAX1_MAGIC, XML_SAX2_MAGIC */
152
NULL, /* startElementNs */
153
NULL, /* endElementNs */
154
NULL /* xmlStructuredErrorFunc */
155
#endif /* _SAX2_BENCHMARK */
63
159
void initXML(struct TestData *td) {
70
166
void parseXML(struct TestData *td, unsigned long iter) {
71
xmlSAXUserParseMemory(&handler,NULL,td->xml,td->xmllen);
168
xmlSAXUserParseMemory(&count_handler,NULL,td->xml,td->xmllen);
169
// printf("Sum: %lf\n", res_total);
171
xmlSAXUserParseMemory(&handler,NULL,td->xml,td->xmllen);
74
175
int main(int argc, char *argv[]) {