/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk
1 by Suren A. Chilingaryan
Initial import
1
#include <stdlib.h>
2
#include <unistd.h>
3
#include <sys/types.h>
4
#include <sys/time.h>
5
#include <stdio.h>
6
#include <string.h>
7
#include <sys/stat.h>
8
#include "asm-xml.h"
9
10
#include "tools.h"
11
12
#define chunkSize 16777216
13
14
AXClassContext  classContext;
15
AXElementClass* docClass;
16
9 by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers
17
inline double walker_process_node(AXElement *cur_node, int siblings) {
18
    AXElement *node;
19
    int i, size;
20
    double res = 0;
21
22
/*
23
    printf("Node: %i\nSubnodes: ", cur_node->id);
24
    for (i=0,node = cur_node->firstChild; node; node = node->nextSibling) {
25
	printf("%i ", node->id);
26
    }
27
    printf("= %i\n", i);
28
*/
29
    switch (cur_node->id) {
30
	case 1:
31
	    if (siblings<4) return 0;
32
	    size = 2;
33
	break;
34
	case 2:
35
	case 3:
36
	    size = 4;
37
	break;
38
	default:
39
	    return 0;
40
    }
41
42
//    printf("Node: %i, size: %i, siblings: %i\n", cur_node->id, size, siblings);
43
44
    for (i=0; i<size; i++) {
45
//	char tmp[256];
46
//	int len = cur_node->attributes[i].limit - cur_node->attributes[i].begin;
47
//	printf("%p %p %i\n", cur_node->attributes[i].begin, cur_node->attributes[i].limit, len);
48
	res += get_value_0(cur_node->attributes[i].begin, cur_node->attributes[i].limit - cur_node->attributes[i].begin);
49
//	strncpy(tmp, cur_node->attributes[i].begin, len);tmp[len]=0;
50
//	puts(tmp);
51
    }
52
    
53
    return res;
54
}
55
56
double walker(AXElement *node) {
57
    int i = 0;
58
    double res = 0;
59
    AXElement *cur_node;
60
61
    for (cur_node = node; cur_node; cur_node = cur_node->nextSibling) {
62
	if (++i>3) break;
63
    }
64
65
//    printf("Node %i Subnodes: %i\n", node->id, i);
66
67
    for (cur_node = node; cur_node; cur_node = cur_node->nextSibling) {
68
	if (cur_node->id) {
69
	    res += walker_process_node(cur_node,i);
70
	}
71
	if (cur_node->firstChild) {
72
	    res += walker(cur_node->firstChild);
73
	}
74
    }
75
    return res;
76
}
77
78
79
const char *schema_file = NULL;
1 by Suren A. Chilingaryan
Initial import
80
void initXML(struct TestData *td) {
81
    struct stat st;
9 by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers
82
    char *schema = NULL;
1 by Suren A. Chilingaryan
Initial import
83
    
84
    if (!strcmp(td->fn, "xmlgen")) {
85
	schema = ReadFile("../xml.files/generated.schema");
9 by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers
86
    } else if (schema_file) {
87
	if (walk_tree) {
88
	    printf("Asmxml needs custom code for each schema, therefore nothing but xmlgen is supported\n");
1 by Suren A. Chilingaryan
Initial import
89
	    exit(1);
90
	}
9 by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers
91
	schema = ReadFile(schema_file);
92
    }
93
94
    if (!schema) {
95
        printf("Schema file is not found\n");
96
        exit(1);
1 by Suren A. Chilingaryan
Initial import
97
    }
98
    
99
    ax_initialize((void*)malloc, (void*)free);
100
101
    int res = ax_initializeClassParser(&classContext);
102
    if (res) {
103
	printf("Initialization failed: %i\n", res);
104
	exit(1);
105
    }
106
    
107
    docClass = ax_classFromString(schema+sizeof(unsigned long), &classContext);
108
    if( docClass == NULL ) {
109
	printf("Schema parse is failed\n");
110
	exit(1);
111
    }
112
113
    free(schema);
114
115
}
116
117
118
119
void releaseXML(struct TestData *td) {
120
    ax_releaseClassParser(&classContext);
121
}
122
123
124
void parseXML(struct TestData *td, unsigned long iter) {
125
    AXParseContext parseContext;
126
    AXElement *root;
127
    
128
    int res = ax_initializeParser(&parseContext, chunkSize);
129
    if( res != 0 ) {
130
	printf("Parser initialization is failed\n");
131
	exit(1);
132
    }
133
134
    root = ax_parse(&parseContext, td->xml, docClass, 1);
135
    if( root == NULL ) {
136
	printf("Parsing is failed\n");
137
	exit(1);
138
    }
139
    
9 by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers
140
    if (walk_tree) {
141
	double res = walker(root);
142
//	printf("Sum: %lf\n", res);
143
    }
144
    
1 by Suren A. Chilingaryan
Initial import
145
    ax_releaseParser(&parseContext);
146
}
147
148
int main(int argc, char *argv[]) {
9 by Suren A. Chilingaryan
Implement DOM walking mode for parsing benchmark in fast parsers
149
    if (argc > 3) schema_file = argv[3];
150
    
1 by Suren A. Chilingaryan
Initial import
151
    return Test(argc,argv);
152
}