/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 create/tools.h

  • Committer: Suren A. Chilingaryan
  • Date: 2009-02-16 09:27:17 UTC
  • Revision ID: csa@dside.dyndns.org-20090216092717-wipyvaaw2srxhgns
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <unistd.h>
 
3
#include <sys/types.h>
 
4
#include <sys/stat.h>
 
5
#include "../tools/disp.h"
 
6
 
 
7
struct TestData {
 
8
    unsigned long iterations;
 
9
    unsigned long inc;
 
10
};
 
11
 
 
12
char *ReadFile(char *fn) {
 
13
    FILE *f;
 
14
    struct stat st;
 
15
    char *buf;
 
16
    
 
17
    f=fopen(fn,"r");
 
18
    if (!f) {
 
19
        printf("Can't open XML file!\n");
 
20
        exit(1);
 
21
    }
 
22
    fstat(f->_fileno,&st);
 
23
    buf=(char*)malloc(st.st_size+1+sizeof(unsigned long));
 
24
    if (!buf) {
 
25
        printf("Can't allocate memory!\n");
 
26
        exit(1);
 
27
    }
 
28
    ((unsigned long*)buf)[0]=st.st_size;
 
29
    fread(buf+sizeof(unsigned long),st.st_size,1,f);
 
30
    fclose(f);
 
31
    buf[st.st_size+sizeof(unsigned long)]=0;
 
32
    return buf;
 
33
}
 
34
 
 
35
void ReadConfig(struct TestData *td) {
 
36
    FILE *f;
 
37
    f=fopen("config","r");
 
38
    if (!f) {
 
39
        printf("Error opening config file!\n");
 
40
        exit(1);
 
41
    }
 
42
    fscanf(f,"%lu",&(td->iterations));
 
43
    fclose(f);
 
44
}
 
45
 
 
46
void initXML(struct TestData *td);
 
47
void releaseXML(struct TestData *td);
 
48
void parseXML(struct TestData *td, unsigned long iter);
 
49
 
 
50
void Usage(char *myname) {
 
51
    fprintf(stderr,"Usage:\n\t%s <iterations> [size increase]\n",myname);
 
52
    exit(0);
 
53
}
 
54
 
 
55
int Test(int argc, char *argv[]) {
 
56
    int i,j;
 
57
    struct timeval pre_time,post_time;
 
58
    struct timezone tz;
 
59
    unsigned long time;
 
60
    struct TestData td;
 
61
 
 
62
    if (argc>=2) td.iterations=atol(argv[1]);
 
63
    else Usage(argv[0]);
 
64
    if (argc==3) td.inc=atol(argv[2]);
 
65
    else td.inc=0;
 
66
 
 
67
    initXML(&td);
 
68
    parseXML(&td,0);
 
69
    
 
70
    disp_init();
 
71
    for (i=1;i<=td.iterations;i++) {
 
72
        gettimeofday(&pre_time,NULL);
 
73
        parseXML(&td,i);
 
74
        gettimeofday(&post_time,NULL);
 
75
        time=(post_time.tv_sec-pre_time.tv_sec)*1000000+(post_time.tv_usec-pre_time.tv_usec);
 
76
        disp_event(time);
 
77
//      printf("%lu\n",time);
 
78
    }
 
79
    disp_post();
 
80
    
 
81
    releaseXML(&td);
 
82
    
 
83
    printf("Building DOM tree in %.3lf(%.2lf) ms!\n",((double)disp_m) / 1000,300*disp_d/disp_m);
 
84
 
 
85
    return 0;
 
86
}
 
87