2003-09-04 12:01:54 -04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "expat.h"
|
|
|
|
|
2007-06-03 11:00:09 -04:00
|
|
|
#if defined(__amigaos__) && defined(__USE_INLINE__)
|
|
|
|
#include <proto/expat.h>
|
|
|
|
#endif
|
|
|
|
|
2006-01-01 16:17:41 -05:00
|
|
|
#ifdef XML_LARGE_SIZE
|
|
|
|
#define XML_FMT_INT_MOD "ll"
|
|
|
|
#else
|
|
|
|
#define XML_FMT_INT_MOD "l"
|
|
|
|
#endif
|
|
|
|
|
2003-09-04 12:01:54 -04:00
|
|
|
static void
|
|
|
|
usage(const char *prog, int rc)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"usage: %s [-n] filename bufferSize nr_of_loops\n", prog);
|
|
|
|
exit(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
XML_Parser parser;
|
|
|
|
char *XMLBuf, *XMLBufEnd, *XMLBufPtr;
|
|
|
|
FILE *fd;
|
|
|
|
struct stat fileAttr;
|
|
|
|
int nrOfLoops, bufferSize, fileSize, i, isFinal;
|
|
|
|
int j = 0, ns = 0;
|
|
|
|
clock_t tstart, tend;
|
|
|
|
double cpuTime = 0.0;
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
if (argv[1][0] == '-') {
|
|
|
|
if (argv[1][1] == 'n' && argv[1][2] == '\0') {
|
|
|
|
ns = 1;
|
|
|
|
j = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
usage(argv[0], 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc != j + 4)
|
|
|
|
usage(argv[0], 1);
|
|
|
|
|
|
|
|
if (stat (argv[j + 1], &fileAttr) != 0) {
|
|
|
|
fprintf (stderr, "could not access file '%s'\n", argv[j + 1]);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = fopen (argv[j + 1], "r");
|
|
|
|
if (!fd) {
|
|
|
|
fprintf (stderr, "could not open file '%s'\n", argv[j + 1]);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
bufferSize = atoi (argv[j + 2]);
|
|
|
|
nrOfLoops = atoi (argv[j + 3]);
|
|
|
|
if (bufferSize <= 0 || nrOfLoops <= 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
"buffer size and nr of loops must be greater than zero.\n");
|
|
|
|
exit(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLBuf = malloc (fileAttr.st_size);
|
|
|
|
fileSize = fread (XMLBuf, sizeof (char), fileAttr.st_size, fd);
|
|
|
|
fclose (fd);
|
|
|
|
|
2006-04-07 16:25:43 -04:00
|
|
|
if (ns)
|
|
|
|
parser = XML_ParserCreateNS(NULL, '!');
|
|
|
|
else
|
|
|
|
parser = XML_ParserCreate(NULL);
|
|
|
|
|
2003-09-04 12:01:54 -04:00
|
|
|
i = 0;
|
|
|
|
XMLBufEnd = XMLBuf + fileSize;
|
|
|
|
while (i < nrOfLoops) {
|
|
|
|
XMLBufPtr = XMLBuf;
|
|
|
|
isFinal = 0;
|
|
|
|
tstart = clock();
|
|
|
|
do {
|
|
|
|
int parseBufferSize = XMLBufEnd - XMLBufPtr;
|
|
|
|
if (parseBufferSize <= bufferSize)
|
|
|
|
isFinal = 1;
|
|
|
|
else
|
|
|
|
parseBufferSize = bufferSize;
|
|
|
|
if (!XML_Parse (parser, XMLBufPtr, parseBufferSize, isFinal)) {
|
2006-01-01 16:17:41 -05:00
|
|
|
fprintf (stderr, "error '%s' at line %" XML_FMT_INT_MOD \
|
|
|
|
"u character %" XML_FMT_INT_MOD "u\n",
|
2003-09-04 12:01:54 -04:00
|
|
|
XML_ErrorString (XML_GetErrorCode (parser)),
|
|
|
|
XML_GetCurrentLineNumber (parser),
|
|
|
|
XML_GetCurrentColumnNumber (parser));
|
|
|
|
free (XMLBuf);
|
|
|
|
XML_ParserFree (parser);
|
|
|
|
exit (4);
|
|
|
|
}
|
|
|
|
XMLBufPtr += bufferSize;
|
|
|
|
} while (!isFinal);
|
|
|
|
tend = clock();
|
|
|
|
cpuTime += ((double) (tend - tstart)) / CLOCKS_PER_SEC;
|
2006-04-07 16:25:43 -04:00
|
|
|
XML_ParserReset(parser, NULL);
|
2003-09-04 12:01:54 -04:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2006-04-07 16:25:43 -04:00
|
|
|
XML_ParserFree (parser);
|
2003-09-04 12:01:54 -04:00
|
|
|
free (XMLBuf);
|
|
|
|
|
|
|
|
printf ("%d loops, with buffer size %d. Average time per loop: %f\n",
|
|
|
|
nrOfLoops, bufferSize, cpuTime / (double) nrOfLoops);
|
|
|
|
return 0;
|
|
|
|
}
|