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 parser
= XML_ParserCreateNS(NULL
, '!');
78 parser
= XML_ParserCreate(NULL
);
81 XMLBufEnd
= XMLBuf
+ fileSize
;
82 while (i
< nrOfLoops
) {
87 int parseBufferSize
= XMLBufEnd
- XMLBufPtr
;
88 if (parseBufferSize
<= bufferSize
)
91 parseBufferSize
= bufferSize
;
92 if (!XML_Parse (parser
, XMLBufPtr
, parseBufferSize
, isFinal
)) {
93 fprintf (stderr
, "error '%s' at line %" XML_FMT_INT_MOD \
94 "u character %" XML_FMT_INT_MOD
"u\n",
95 XML_ErrorString (XML_GetErrorCode (parser
)),
96 XML_GetCurrentLineNumber (parser
),
97 XML_GetCurrentColumnNumber (parser
));
99 XML_ParserFree (parser
);
102 XMLBufPtr
+= bufferSize
;
105 cpuTime
+= ((double) (tend
- tstart
)) / CLOCKS_PER_SEC
;
106 XML_ParserReset(parser
, NULL
);
110 XML_ParserFree (parser
);
113 printf ("%d loops, with buffer size %d. Average time per loop: %f\n",
114 nrOfLoops
, bufferSize
, cpuTime
/ (double) nrOfLoops
);