]> matita.cs.unibo.it Git - helm.git/commitdiff
added parse test for
authorStefano Zacchiroli <zack@upsilon.cc>
Mon, 22 Nov 2004 17:20:15 +0000 (17:20 +0000)
committerStefano Zacchiroli <zack@upsilon.cc>
Mon, 22 Nov 2004 17:20:15 +0000 (17:20 +0000)
- expat
- libxml2 (xmlreader API)
- libxml2 (SAX2 API)

helm/papers/use_case/stats/parse/.cvsignore [new file with mode: 0644]
helm/papers/use_case/stats/parse/Makefile [new file with mode: 0644]
helm/papers/use_case/stats/parse/parse_expat.c [new file with mode: 0644]
helm/papers/use_case/stats/parse/parse_xmlreader.c [new file with mode: 0644]
helm/papers/use_case/stats/parse/parse_xmlsax.c [new file with mode: 0644]

diff --git a/helm/papers/use_case/stats/parse/.cvsignore b/helm/papers/use_case/stats/parse/.cvsignore
new file mode 100644 (file)
index 0000000..8663981
--- /dev/null
@@ -0,0 +1,3 @@
+parse_expat
+parse_xmlreader
+parse_xmlsax
diff --git a/helm/papers/use_case/stats/parse/Makefile b/helm/papers/use_case/stats/parse/Makefile
new file mode 100644 (file)
index 0000000..9c889e0
--- /dev/null
@@ -0,0 +1,13 @@
+CC = gcc
+LIBXML_FLAGS = `pkg-config --cflags --libs libxml-2.0`
+EXPAT_FLAGS = -lexpat
+BIN = parse_expat parse_xmlreader parse_xmlsax
+all: $(BIN)
+clean:
+       rm -f $(BIN)
+parse_expat: parse_expat.c
+       $(CC) $(EXPAT_FLAGS) -o $@ $<
+parse_xmlreader: parse_xmlreader.c
+       $(CC) $(LIBXML_FLAGS) -o $@ $<
+parse_xmlsax: parse_xmlsax.c
+       $(CC) $(LIBXML_FLAGS) -o $@ $<
diff --git a/helm/papers/use_case/stats/parse/parse_expat.c b/helm/papers/use_case/stats/parse/parse_expat.c
new file mode 100644 (file)
index 0000000..9008887
--- /dev/null
@@ -0,0 +1,50 @@
+#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;
+}
+
diff --git a/helm/papers/use_case/stats/parse/parse_xmlreader.c b/helm/papers/use_case/stats/parse/parse_xmlreader.c
new file mode 100644 (file)
index 0000000..e154b70
--- /dev/null
@@ -0,0 +1,31 @@
+#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;
+}
+
diff --git a/helm/papers/use_case/stats/parse/parse_xmlsax.c b/helm/papers/use_case/stats/parse/parse_xmlsax.c
new file mode 100644 (file)
index 0000000..334a42e
--- /dev/null
@@ -0,0 +1,98 @@
+#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;
+}
+