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
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "../tools/disp.h"
struct TestData {
unsigned long iterations;
unsigned long inc;
char memory_bench;
};
char *ReadFile(char *fn) {
FILE *f;
struct stat st;
char *buf;
f=fopen(fn,"r");
if (!f) {
printf("Can't open XML file!\n");
exit(1);
}
fstat(f->_fileno,&st);
buf=(char*)malloc(st.st_size+1+sizeof(unsigned long));
if (!buf) {
printf("Can't allocate memory!\n");
exit(1);
}
((unsigned long*)buf)[0]=st.st_size;
fread(buf+sizeof(unsigned long),st.st_size,1,f);
fclose(f);
buf[st.st_size+sizeof(unsigned long)]=0;
return buf;
}
void ReadConfig(struct TestData *td) {
FILE *f;
f=fopen("config","r");
if (!f) {
printf("Error opening config file!\n");
exit(1);
}
fscanf(f,"%lu",&(td->iterations));
fclose(f);
}
void initXML(struct TestData *td);
void releaseXML(struct TestData *td);
void parseXML(struct TestData *td, unsigned long iter);
void Usage(char *myname) {
fprintf(stderr,"Usage:\n\t%s <iterations> [size increase]\n",myname);
exit(0);
}
int Test(int argc, char *argv[]) {
int i,j;
struct timeval pre_time,post_time;
struct timezone tz;
unsigned long time;
struct TestData td;
int execute_xml = 1;
if (getenv("skip_xml")) execute_xml = 0;
if (getenv("memory_bench")) td.memory_bench = 1;
else td.memory_bench = 0;
if (argc>=2) td.iterations=atol(argv[1]);
else Usage(argv[0]);
if (argc>3) td.inc=atol(argv[3]);
else if (argc==3) td.inc=atol(argv[2]);
else td.inc=0;
initXML(&td);
if (execute_xml) parseXML(&td,0);
disp_init();
for (i=1;i<=td.iterations;i++) {
gettimeofday(&pre_time,NULL);
if (execute_xml) parseXML(&td,i);
gettimeofday(&post_time,NULL);
time=(post_time.tv_sec-pre_time.tv_sec)*1000000+(post_time.tv_usec-pre_time.tv_usec);
disp_event(time);
// printf("%lu\n",time);
}
disp_post();
releaseXML(&td);
printf("Building DOM tree in %.3lf(%.2lf) ms!\n",((double)disp_m) / 1000,300*disp_d/disp_m);
return 0;
}
|