]>
git.saurik.com Git - wxWidgets.git/blob - src/expat/tests/benchmark/benchmark.c
7 #if defined(__amigaos__) && defined(__USE_INLINE__)
8 #include <proto/expat.h>
12 #define XML_FMT_INT_MOD "ll"
14 #define XML_FMT_INT_MOD "l"
18 usage(const char *prog
, int rc
)
21 "usage: %s [-n] filename bufferSize nr_of_loops\n", prog
);
25 int main (int argc
, char *argv
[])
28 char *XMLBuf
, *XMLBufEnd
, *XMLBufPtr
;
31 int nrOfLoops
, bufferSize
, fileSize
, i
, isFinal
;
37 if (argv
[1][0] == '-') {
38 if (argv
[1][1] == 'n' && argv
[1][2] == '\0') {
50 if (stat (argv
[j
+ 1], &fileAttr
) != 0) {
51 fprintf (stderr
, "could not access file '%s'\n", argv
[j
+ 1]);
55 fd
= fopen (argv
[j
+ 1], "r");
57 fprintf (stderr
, "could not open file '%s'\n", argv
[j
+ 1]);
61 bufferSize
= atoi (argv
[j
+ 2]);
62 nrOfLoops
= atoi (argv
[j
+ 3]);
63 if (bufferSize
<= 0 || nrOfLoops
<= 0) {
65 "buffer size and nr of loops must be greater than zero.\n");
69 XMLBuf
= malloc (fileAttr
.st_size
);
70 fileSize
= fread (XMLBuf
, sizeof (char), fileAttr
.st_size
, fd
);
74 parser
= XML_ParserCreateNS(NULL
, '!');
76 parser
= XML_ParserCreate(NULL
);
79 XMLBufEnd
= XMLBuf
+ fileSize
;
80 while (i
< nrOfLoops
) {
85 int parseBufferSize
= XMLBufEnd
- XMLBufPtr
;
86 if (parseBufferSize
<= bufferSize
)
89 parseBufferSize
= bufferSize
;
90 if (!XML_Parse (parser
, XMLBufPtr
, parseBufferSize
, isFinal
)) {
91 fprintf (stderr
, "error '%s' at line %" XML_FMT_INT_MOD \
92 "u character %" XML_FMT_INT_MOD
"u\n",
93 XML_ErrorString (XML_GetErrorCode (parser
)),
94 XML_GetCurrentLineNumber (parser
),
95 XML_GetCurrentColumnNumber (parser
));
97 XML_ParserFree (parser
);
100 XMLBufPtr
+= bufferSize
;
103 cpuTime
+= ((double) (tend
- tstart
)) / CLOCKS_PER_SEC
;
104 XML_ParserReset(parser
, NULL
);
108 XML_ParserFree (parser
);
111 printf ("%d loops, with buffer size %d. Average time per loop: %f\n",
112 nrOfLoops
, bufferSize
, cpuTime
/ (double) nrOfLoops
);