/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/asmxml.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:
14
14
AXClassContext  classContext;
15
15
AXElementClass* docClass;
16
16
 
 
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;
17
80
void initXML(struct TestData *td) {
18
81
    struct stat st;
19
 
    char *schema;
 
82
    char *schema = NULL;
20
83
    
21
84
    if (!strcmp(td->fn, "xmlgen")) {
22
85
        schema = ReadFile("../xml.files/generated.schema");
23
 
        if (!schema) {
24
 
            printf("Schema file is not found\n");
 
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");
25
89
            exit(1);
26
90
        }
27
 
        
 
91
        schema = ReadFile(schema_file);
 
92
    }
 
93
 
 
94
    if (!schema) {
 
95
        printf("Schema file is not found\n");
 
96
        exit(1);
28
97
    }
29
98
    
30
99
    ax_initialize((void*)malloc, (void*)free);
68
137
        exit(1);
69
138
    }
70
139
    
 
140
    if (walk_tree) {
 
141
        double res = walker(root);
 
142
//      printf("Sum: %lf\n", res);
 
143
    }
 
144
    
71
145
    ax_releaseParser(&parseContext);
72
146
}
73
147
 
74
148
int main(int argc, char *argv[]) {
 
149
    if (argc > 3) schema_file = argv[3];
 
150
    
75
151
    return Test(argc,argv);
76
152
}