/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to parse/libxml-sax.c

  • Committer: Suren A. Chilingaryan
  • Date: 2009-10-01 15:56:11 UTC
  • Revision ID: csa@dside.dyndns.org-20091001155611-9g3f1yad2w195t4g
Implement DOM walking mode for parsing benchmark in fast parsers

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#define _SAX2_BENCHMARK
10
10
#endif
11
11
 
 
12
 
12
13
void startElement_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) {
13
 
    return;
14
14
}
15
 
 
16
15
void endElement_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) {
17
 
    return;
18
16
}
19
17
void characters_(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) {
 
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
    }
20
76
    return;
21
77
}
22
78
 
60
116
#endif /* _SAX2_BENCHMARK */
61
117
};
62
118
 
 
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
 
63
159
void initXML(struct TestData *td) {
64
160
}
65
161
 
68
164
}
69
165
 
70
166
void parseXML(struct TestData *td, unsigned long iter) {
71
 
    xmlSAXUserParseMemory(&handler,NULL,td->xml,td->xmllen);
 
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
    }
72
173
}
73
174
 
74
175
int main(int argc, char *argv[]) {