8 #define XML_FMT_INT_MOD "ll"
10 #define XML_FMT_INT_MOD "l"
14 usage(const char *prog
, int rc
)
17 "usage: %s [-n] filename bufferSize nr_of_loops\n", prog
);
21 #ifdef AMIGA_SHARED_LIB
22 #include <proto/expat.h>
24 amiga_main(int argc
, char *argv
[])
26 int main (int argc
, char *argv
[])
30 char *XMLBuf
, *XMLBufEnd
, *XMLBufPtr
;
33 int nrOfLoops
, bufferSize
, fileSize
, i
, isFinal
;
39 if (argv
[1][0] == '-') {
40 if (argv
[1][1] == 'n' && argv
[1][2] == '\0') {
52 if (stat (argv
[j
+ 1], &fileAttr
) != 0) {
53 fprintf (stderr
, "could not access file '%s'\n", argv
[j
+ 1]);
57 fd
= fopen (argv
[j
+ 1], "r");
59 fprintf (stderr
, "could not open file '%s'\n", argv
[j
+ 1]);
63 bufferSize
= atoi (argv
[j
+ 2]);
64 nrOfLoops
= atoi (argv
[j
+ 3]);
65 if (bufferSize
<= 0 || nrOfLoops
<= 0) {
67 "buffer size and nr of loops must be greater than zero.\n");
71 XMLBuf
= malloc (fileAttr
.st_size
);
72 fileSize
= fread (XMLBuf
, sizeof (char), fileAttr
.st_size
, fd
);
76 XMLBufEnd
= XMLBuf
+ fileSize
;
77 while (i
< nrOfLoops
) {
81 parser
= XML_ParserCreateNS(NULL
, '!');
83 parser
= XML_ParserCreate(NULL
);
86 int parseBufferSize
= XMLBufEnd
- XMLBufPtr
;
87 if (parseBufferSize
<= bufferSize
)
90 parseBufferSize
= bufferSize
;
91 if (!XML_Parse (parser
, XMLBufPtr
, parseBufferSize
, isFinal
)) {
92 fprintf (stderr
, "error '%s' at line %" XML_FMT_INT_MOD \
93 "u character %" XML_FMT_INT_MOD
"u\n",
94 XML_ErrorString (XML_GetErrorCode (parser
)),
95 XML_GetCurrentLineNumber (parser
),
96 XML_GetCurrentColumnNumber (parser
));
98 XML_ParserFree (parser
);
101 XMLBufPtr
+= bufferSize
;
104 cpuTime
+= ((double) (tend
- tstart
)) / CLOCKS_PER_SEC
;
105 XML_ParserFree (parser
);
111 printf ("%d loops, with buffer size %d. Average time per loop: %f\n",
112 nrOfLoops
, bufferSize
, cpuTime
/ (double) nrOfLoops
);