4 / _ \\ /| '_ \ / _` | __|
5 | __// \| |_) | (_| | |_
6 \___/_/\_\ .__/ \__,_|\__|
9 Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
10 Copyright (c) 2000-2017 Expat development team
11 Licensed under the MIT license:
13 Permission is hereby granted, free of charge, to any person obtaining
14 a copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sublicense, and/or sell copies of the Software, and to permit
18 persons to whom the Software is furnished to do so, subject to the
21 The above copyright notice and this permission notice shall be included
22 in all copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
27 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
29 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
30 USE OR OTHER DEALINGS IN THE SOFTWARE.
40 # define XML_FMT_INT_MOD "ll"
42 # define XML_FMT_INT_MOD "l"
45 #ifdef XML_UNICODE_WCHAR_T
46 # define XML_FMT_STR "ls"
48 # define XML_FMT_STR "s"
52 usage(const char *prog, int rc)
55 "usage: %s [-n] filename bufferSize nr_of_loops\n", prog);
59 int main (int argc, char *argv[])
62 char *XMLBuf, *XMLBufEnd, *XMLBufPtr;
65 int nrOfLoops, bufferSize, fileSize, i, isFinal;
71 if (argv[1][0] == '-') {
72 if (argv[1][1] == 'n' && argv[1][2] == '\0') {
84 if (stat (argv[j + 1], &fileAttr) != 0) {
85 fprintf (stderr, "could not access file '%s'\n", argv[j + 1]);
89 fd = fopen (argv[j + 1], "r");
91 fprintf (stderr, "could not open file '%s'\n", argv[j + 1]);
95 bufferSize = atoi (argv[j + 2]);
96 nrOfLoops = atoi (argv[j + 3]);
97 if (bufferSize <= 0 || nrOfLoops <= 0) {
99 "buffer size and nr of loops must be greater than zero.\n");
103 XMLBuf = malloc (fileAttr.st_size);
104 fileSize = fread (XMLBuf, sizeof (char), fileAttr.st_size, fd);
108 parser = XML_ParserCreateNS(NULL, '!');
110 parser = XML_ParserCreate(NULL);
113 XMLBufEnd = XMLBuf + fileSize;
114 while (i < nrOfLoops) {
119 int parseBufferSize = XMLBufEnd - XMLBufPtr;
120 if (parseBufferSize <= bufferSize)
123 parseBufferSize = bufferSize;
124 if (!XML_Parse (parser, XMLBufPtr, parseBufferSize, isFinal)) {
126 "error '%" XML_FMT_STR "' at line %" XML_FMT_INT_MOD \
127 "u character %" XML_FMT_INT_MOD "u\n",
128 XML_ErrorString (XML_GetErrorCode (parser)),
129 XML_GetCurrentLineNumber (parser),
130 XML_GetCurrentColumnNumber (parser));
132 XML_ParserFree (parser);
135 XMLBufPtr += bufferSize;
138 cpuTime += ((double) (tend - tstart)) / CLOCKS_PER_SEC;
139 XML_ParserReset(parser, NULL);
143 XML_ParserFree (parser);
146 printf ("%d loops, with buffer size %d. Average time per loop: %f\n",
147 nrOfLoops, bufferSize, cpuTime / (double) nrOfLoops);