/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <stdio.h>
#include <sys/time.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

#include "tools.h"

#if LIBXML_VERSION > 20600
#define _SAX2_BENCHMARK
#endif


void startElement_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) {
}
void endElement_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) {
}
void characters_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) {
}

double res_total;
double res_attr[MAX_LEVELS+1];
double res_sum[MAX_LEVELS+1];
int res_count[MAX_LEVELS+1];
int level = 0;

void startDocument_c(void * ctx) {
    level = 0;
    res_total = 0;
    res_count[0] = 0;
}

void startElement_c(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) {
    int i;
    double res = 0;

    if (atts) {
	for (i = 0; atts[i]; i++) {
	    res = get_value(atts[i]);
	    if (res) break;
	}
    }

//    printf("%i %lf\n", level, res);
    res_attr[level] = res;
    if (++level == MAX_LEVELS) {
	printf("XML structure is too deep, only %i levels are supported\n", MAX_LEVELS);
	exit(1);
    }
    res_count[level]=0;
    
    return;
}

void endElement_c(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) {
//    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]);
    if (res_count[level] > 3) {
	res_total += res_sum[level];
    }
    
    --level;
    if (res_count[level]) {
	res_sum[level]+=res_attr[level];
    } else {
	res_sum[level]=res_attr[level];
    }
    ++res_count[level];

    return;
}

void characters_c(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) {
    if (ch) {
	double res = get_value_0(ch,len);
	if (res) res_attr[level-1] = res;
    }
    return;
}


xmlSAXHandler handler = {
    NULL, /* internalSubset */
    NULL, /* isStandalone */
    NULL, /* hasInternalSubset */
    NULL, /* hasExternalSubset */
    NULL, /* resolveEntity */
    NULL, /* getEntity */
    NULL, /* entityDecl */
    NULL, /* notationDecl */
    NULL, /* attributeDecl */
    NULL, /* elementDecl */
    NULL, /* unparsedEntityDecl */
    NULL, /* setDocumentLocator */
    NULL, /* startDocument */
    NULL, /* endDocument */
    startElement_, /* startElement */
    endElement_, /* endElement */
    NULL, /* reference */
    characters_, /* characters */
    NULL, /* ignorableWhitespace */
    NULL, /* processingInstruction */
    NULL, /* comment */
    NULL, /* xmlParserWarning */
    NULL, /* xmlParserError */
    NULL, /* xmlParserError */
    NULL, /* getParameterEntity */
    NULL, /* cdataBlock; */
    NULL, /* externalSubset; */
#ifndef _SAX2_BENCHMARK
    1
#else
    XML_SAX2_MAGIC,    /* XML_SAX1_MAGIC, XML_SAX2_MAGIC */
    NULL,
    NULL, /* startElementNs */
    NULL, /* endElementNs */
    NULL  /* xmlStructuredErrorFunc */
#endif /* _SAX2_BENCHMARK */
};

xmlSAXHandler count_handler = {
    NULL, /* internalSubset */
    NULL, /* isStandalone */
    NULL, /* hasInternalSubset */
    NULL, /* hasExternalSubset */
    NULL, /* resolveEntity */
    NULL, /* getEntity */
    NULL, /* entityDecl */
    NULL, /* notationDecl */
    NULL, /* attributeDecl */
    NULL, /* elementDecl */
    NULL, /* unparsedEntityDecl */
    NULL, /* setDocumentLocator */
    startDocument_c, /* startDocument */
    NULL, /* endDocument */
    startElement_c, /* startElement */
    endElement_c, /* endElement */
    NULL, /* reference */
    characters_c, /* characters */
    NULL, /* ignorableWhitespace */
    NULL, /* processingInstruction */
    NULL, /* comment */
    NULL, /* xmlParserWarning */
    NULL, /* xmlParserError */
    NULL, /* xmlParserError */
    NULL, /* getParameterEntity */
    NULL, /* cdataBlock; */
    NULL, /* externalSubset; */
#ifndef _SAX2_BENCHMARK
    1
#else
    XML_SAX2_MAGIC,    /* XML_SAX1_MAGIC, XML_SAX2_MAGIC */
    NULL,
    NULL, /* startElementNs */
    NULL, /* endElementNs */
    NULL  /* xmlStructuredErrorFunc */
#endif /* _SAX2_BENCHMARK */
};


void initXML(struct TestData *td) {
}

void releaseXML(struct TestData *td) {
    xmlCleanupParser();
}

void parseXML(struct TestData *td, unsigned long iter) {
    if (walk_tree) {
	xmlSAXUserParseMemory(&count_handler,NULL,td->xml,td->xmllen);
//	printf("Sum: %lf\n", res_total);
    } else {
	xmlSAXUserParseMemory(&handler,NULL,td->xml,td->xmllen);
    }
}

int main(int argc, char *argv[]) {
    return Test(argc,argv);
}