I wanted to see the real speed at the SAX interface after a little too
* testSAX.c: I wanted to see the real speed at the SAX interface
after a little too many Ximianer started complaining about the
parser speed.
added a --quiet option:
paphio:~/XML -> ls -l db100000.xml
-rw-rw-r-- 1 veillard www 20182040 Mar 20 10:30 db100000.xml
paphio:~/XML -> time ./testSAX --quiet db100000.xml
3200006 callbacks generated
real 0m1.270s
Which means 16MBytes/s and 3Mcallback/s
Daniel
diff --git a/testSAX.c b/testSAX.c
index 559177c..cf28467 100644
--- a/testSAX.c
+++ b/testSAX.c
@@ -45,6 +45,8 @@
static int push = 0;
static int speed = 0;
static int noent = 0;
+static int quiet = 0;
+static int callbacks = 0;
xmlSAXHandler emptySAXHandlerStruct = {
NULL, /* internalSubset */
@@ -97,6 +99,9 @@
static int
isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED)
{
+ callbacks++;
+ if (quiet)
+ return(0);
fprintf(stdout, "SAX.isStandalone()\n");
return(0);
}
@@ -112,6 +117,9 @@
static int
hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
{
+ callbacks++;
+ if (quiet)
+ return(0);
fprintf(stdout, "SAX.hasInternalSubset()\n");
return(0);
}
@@ -127,6 +135,9 @@
static int
hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
{
+ callbacks++;
+ if (quiet)
+ return(0);
fprintf(stdout, "SAX.hasExternalSubset()\n");
return(0);
}
@@ -141,6 +152,9 @@
internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.internalSubset(%s,", name);
if (ExternalID == NULL)
fprintf(stdout, " ,");
@@ -162,6 +176,9 @@
externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.externalSubset(%s,", name);
if (ExternalID == NULL)
fprintf(stdout, " ,");
@@ -190,6 +207,9 @@
static xmlParserInputPtr
resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId)
{
+ callbacks++;
+ if (quiet)
+ return(NULL);
/* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
@@ -222,6 +242,9 @@
static xmlEntityPtr
getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
{
+ callbacks++;
+ if (quiet)
+ return(NULL);
fprintf(stdout, "SAX.getEntity(%s)\n", name);
return(NULL);
}
@@ -238,6 +261,9 @@
static xmlEntityPtr
getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
{
+ callbacks++;
+ if (quiet)
+ return(NULL);
fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
return(NULL);
}
@@ -258,6 +284,9 @@
entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
name, type, publicId, systemId, content);
}
@@ -275,6 +304,9 @@
int type, int def, const xmlChar *defaultValue,
xmlEnumerationPtr tree ATTRIBUTE_UNUSED)
{
+ callbacks++;
+ if (quiet)
+ return;
if (defaultValue == NULL)
fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n",
elem, name, type, def);
@@ -296,6 +328,9 @@
elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
xmlElementContentPtr content ATTRIBUTE_UNUSED)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
name, type);
}
@@ -313,6 +348,9 @@
notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
const xmlChar *publicId, const xmlChar *systemId)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
(char *) name, (char *) publicId, (char *) systemId);
}
@@ -332,6 +370,9 @@
const xmlChar *publicId, const xmlChar *systemId,
const xmlChar *notationName)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
(char *) name, (char *) publicId, (char *) systemId,
(char *) notationName);
@@ -348,6 +389,9 @@
static void
setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.setDocumentLocator()\n");
}
@@ -360,6 +404,9 @@
static void
startDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.startDocument()\n");
}
@@ -372,6 +419,9 @@
static void
endDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.endDocument()\n");
}
@@ -387,6 +437,9 @@
{
int i;
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.startElement(%s", (char *) name);
if (atts != NULL) {
for (i = 0;(atts[i] != NULL);i++) {
@@ -408,6 +461,9 @@
static void
endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
}
@@ -426,6 +482,9 @@
char output[40];
int i;
+ callbacks++;
+ if (quiet)
+ return;
for (i = 0;(i<len) && (i < 30);i++)
output[i] = ch[i];
output[i] = 0;
@@ -443,6 +502,9 @@
static void
referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.reference(%s)\n", name);
}
@@ -462,6 +524,9 @@
char output[40];
int i;
+ callbacks++;
+ if (quiet)
+ return;
for (i = 0;(i<len) && (i < 30);i++)
output[i] = ch[i];
output[i] = 0;
@@ -481,6 +546,9 @@
processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target,
const xmlChar *data)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
(char *) target, (char *) data);
}
@@ -496,6 +564,9 @@
static void
cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.pcdata(%.20s, %d)\n",
(char *) value, len);
}
@@ -510,6 +581,9 @@
static void
commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value)
{
+ callbacks++;
+ if (quiet)
+ return;
fprintf(stdout, "SAX.comment(%s)\n", value);
}
@@ -527,6 +601,9 @@
{
va_list args;
+ callbacks++;
+ if (quiet)
+ return;
va_start(args, msg);
fprintf(stdout, "SAX.warning: ");
vfprintf(stdout, msg, args);
@@ -547,6 +624,9 @@
{
va_list args;
+ callbacks++;
+ if (quiet)
+ return;
va_start(args, msg);
fprintf(stdout, "SAX.error: ");
vfprintf(stdout, msg, args);
@@ -567,6 +647,9 @@
{
va_list args;
+ callbacks++;
+ if (quiet)
+ return;
va_start(args, msg);
fprintf(stdout, "SAX.fatalError: ");
vfprintf(stdout, msg, args);
@@ -673,18 +756,23 @@
/*
* Empty callbacks for checking
*/
- res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
- if (res != 0) {
- fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
+ if (!quiet) {
+ res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
+ if (res != 0) {
+ fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
+ }
}
/*
* Debug callback
*/
+ callbacks = 0;
res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
if (res != 0) {
fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
}
+ if (quiet)
+ fprintf(stdout, "%d callbacks generated\n", callbacks);
} else {
/*
* test 100x the SAX parse
@@ -722,6 +810,9 @@
else if ((!strcmp(argv[i], "-noent")) ||
(!strcmp(argv[i], "--noent")))
noent++;
+ else if ((!strcmp(argv[i], "-quiet")) ||
+ (!strcmp(argv[i], "--quiet")))
+ quiet++;
}
if (noent != 0) xmlSubstituteEntitiesDefault(1);
for (i = 1; i < argc ; i++) {