--- /dev/null
+#include <stdio.h>
+#include <sys/time.h>
+#include <expat.h>
+
+static void XMLCALL
+startElement(void *userData, const char *name, const char **atts) { return; }
+
+static void XMLCALL
+endElement(void *userData, const char *name) { return; }
+
+static void XMLCALL
+characterData(void *userData, const char *s, int len) { return; }
+
+static void XMLCALL
+startCdata(void *userData) { return; }
+
+static void XMLCALL
+endCdata(void *userData) { return; }
+
+int
+main(int argc, char *argv[])
+{
+ char buf[BUFSIZ];
+ int done;
+ FILE *xmlfile = stdin;
+ struct timeval timing1, timing2;
+ XML_Parser parser = XML_ParserCreateNS(NULL,' ');
+ XML_SetElementHandler(parser, startElement, endElement);
+ XML_SetCharacterDataHandler(parser, characterData);
+ XML_SetCdataSectionHandler(parser, startCdata, endCdata);
+ gettimeofday(&timing1, NULL);
+ do {
+ size_t len = fread(buf, 1, sizeof(buf), xmlfile);
+ done = len < sizeof(buf);
+ if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) {
+ fprintf(stderr,
+ "%s at line %d\n",
+ XML_ErrorString(XML_GetErrorCode(parser)),
+ XML_GetCurrentLineNumber(parser));
+ return 1;
+ }
+ } while (!done);
+ gettimeofday(&timing2, NULL) != 0;
+ XML_ParserFree(parser);
+ fprintf(stdout, "%d\n",
+ ((timing2.tv_sec * 1000000 + timing2.tv_usec) -
+ (timing1.tv_sec * 1000000 + timing1.tv_usec)) / 1000);
+ return 0;
+}
+
--- /dev/null
+#include <stdio.h>
+#include <sys/time.h>
+#include <libxml/xmlreader.h>
+
+int
+main(int argc, char *argv[])
+{
+ struct timeval timing1, timing2;
+ xmlTextReaderPtr reader;
+ int ret;
+ reader = xmlReaderForFd(0, NULL, NULL, 0);
+ if (reader == NULL) {
+ fprintf(stderr, "Can't instantiate parser\n");
+ return 1;
+ }
+ gettimeofday(&timing1, NULL);
+ ret = xmlTextReaderRead(reader);
+ while (ret == 1) {
+ ret = xmlTextReaderRead(reader);
+ }
+ gettimeofday(&timing2, NULL);
+ xmlFreeTextReader(reader);
+ if (ret != 0) {
+ fprintf(stderr, "failed to parse STDIN\n");
+ }
+ fprintf(stdout, "%d\n",
+ ((timing2.tv_sec * 1000000 + timing2.tv_usec) -
+ (timing1.tv_sec * 1000000 + timing1.tv_usec)) / 1000);
+ return 0;
+}
+
--- /dev/null
+#include <stdio.h>
+#include <sys/time.h>
+#include <libxml/xmlreader.h>
+
+void characters_cb
+(void * ctx, const xmlChar * ch, int len) { return; }
+
+void whitespace_cb
+(void *ctx, const xmlChar *ch, int len) { return; }
+
+void cdata_cb
+(void *ctx, const xmlChar *value, int len) { return; }
+
+void start_element_cb
+(void *ctx, const xmlChar *name, const xmlChar **atts) { return; }
+
+void start_element_ns_cb
+(void *ctx, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI,
+ int nb_namespaces, const xmlChar **namespaces, int nb_attributes,
+ int nb_defaulted, const xmlChar **attributes)
+{ return; }
+
+void end_element_ns_cb
+(void *ctx, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI)
+{ return; }
+
+void error_cb
+(void *ctx, const char *msg, ...) {
+ fprintf(stderr, "Error: %s\n", msg);
+ return;
+}
+
+int
+main(int argc, char *argv[])
+{
+ char buf[BUFSIZ];
+ int res;
+ int done;
+ FILE *xmlfile = stdin;
+ struct timeval timing1, timing2;
+ xmlParserCtxtPtr ctxt;
+ xmlSAXHandler sax = {
+ NULL, /* internalSubsetSAXFunc */
+ NULL, /* isStandaloneSAXFunc */
+ NULL, /* hasInternalSubsetSAXFunc */
+ NULL, /* hasExternalSubsetSAXFunc */
+ NULL, /* resolveEntitySAXFunc */
+ NULL, /* getEntitySAXFunc */
+ NULL, /* entityDeclSAXFunc */
+ NULL, /* notationDeclSAXFunc */
+ NULL, /* attributeDeclSAXFunc */
+ NULL, /* elementDeclSAXFunc */
+ NULL, /* unparsedEntityDeclSAXFunc */
+ NULL, /* setDocumentLocatorSAXFunc */
+ NULL, /* startDocumentSAXFunc */
+ NULL, /* endDocumentSAXFunc */
+ start_element_cb, /* startElementSAXFunc */
+ NULL, /* endElementSAXFunc */
+ NULL, /* referenceSAXFunc */
+ characters_cb, /* charactersSAXFunc */
+ whitespace_cb, /* ignorableWhitespaceSAXFunc */
+ NULL, /* processingInstructionSAXFunc */
+ NULL, /* commentSAXFunc */
+ NULL, /* warningSAXFunc */
+ error_cb, /* errorSAXFunc */
+ NULL, /* fatalErrorSAXFunc */
+ NULL, /* getParameterEntitySAXFunc */
+ cdata_cb, /* cdataBlockSAXFunc */
+ NULL, /* externalSubsetSAXFunc */
+ XML_SAX2_MAGIC, /* initialized */
+ NULL, /* _private */
+ start_element_ns_cb, /* startElementNsSAX2Func */
+ end_element_ns_cb, /* startElementNsSAX2Func */
+ NULL /* xmlStructuredErrorFunc */
+ };
+ ctxt = xmlCreatePushParserCtxt(&sax, NULL, NULL, 0, NULL);
+ if (ctxt == NULL) {
+ fprintf(stderr, "Can't instantiate parser\n");
+ return 1;
+ }
+ gettimeofday(&timing1, NULL);
+ do {
+ size_t len = fread(buf, 1, sizeof(buf), xmlfile);
+ done = len < sizeof(buf);
+ res = xmlParseChunk(ctxt, buf, len, 0);
+ if (res != 0) {
+ fprintf(stderr, "Parse error\n");
+ return 1;
+ }
+ } while (!done);
+ gettimeofday(&timing2, NULL);
+ xmlFreeParserCtxt(ctxt);
+ fprintf(stdout, "%d\n",
+ ((timing2.tv_sec * 1000000 + timing2.tv_usec) -
+ (timing1.tv_sec * 1000000 + timing1.tv_usec)) / 1000);
+ return 0;
+}
+