summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--relaxng.c14
-rw-r--r--testSAX.c158
3 files changed, 170 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 3599c6f4..5a35219a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Feb 22 23:16:23 CET 2004 Daniel Veillard <daniel@veillard.com>
+
+ * testSAX.c: add --timing option
+ * relaxng.c: use the psvi field of the nodes instead of _private
+ which may be used for other purposes.
+
Sat Feb 21 16:57:48 CET 2004 Daniel Veillard <daniel@veillard.com>
* encoding.c: small patch to try to fix a warning with Sun One compiler
diff --git a/relaxng.c b/relaxng.c
index dcaf8802..4370ef31 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -1536,7 +1536,7 @@ xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt,
}
} else if (IS_RELAXNG(tmp, "include")) {
xmlChar *href = NULL;
- xmlRelaxNGDocumentPtr inc = tmp->_private;
+ xmlRelaxNGDocumentPtr inc = tmp->psvi;
if ((inc != NULL) && (inc->doc != NULL) &&
(inc->doc->children != NULL)) {
@@ -4488,7 +4488,7 @@ xmlRelaxNGParseInclude(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
xmlNodePtr root;
int ret = 0, tmp;
- incl = node->_private;
+ incl = node->psvi;
if (incl == NULL) {
xmlRngPErr(ctxt, node, XML_RNGP_INCLUDE_EMPTY,
"Include node has no data\n", NULL, NULL);
@@ -4612,7 +4612,7 @@ xmlRelaxNGProcessExternalRef(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
int newNs = 0, oldflags;
xmlRelaxNGDefinePtr def;
- docu = node->_private;
+ docu = node->psvi;
if (docu != NULL) {
def = xmlRelaxNGNewDefine(ctxt, node);
if (def == NULL)
@@ -6919,7 +6919,7 @@ xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root)
if (ns != NULL)
xmlFree(ns);
xmlFree(URL);
- cur->_private = docu;
+ cur->psvi = docu;
} else if (xmlStrEqual(cur->name, BAD_CAST "include")) {
xmlChar *href, *ns, *base, *URL;
xmlRelaxNGIncludePtr incl;
@@ -6973,7 +6973,7 @@ xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root)
goto skip_children;
}
xmlFree(URL);
- cur->_private = incl;
+ cur->psvi = incl;
} else if ((xmlStrEqual(cur->name, BAD_CAST "element")) ||
(xmlStrEqual(cur->name, BAD_CAST "attribute")))
{
@@ -9572,7 +9572,7 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt,
* This node was already validated successfully against
* this definition.
*/
- if (node->_private == define) {
+ if (node->psvi == define) {
ctxt->state->seq = xmlRelaxNGSkipIgnored(ctxt, node->next);
if (ctxt->errNr > errNr)
xmlRelaxNGPopErrors(ctxt, errNr);
@@ -9753,7 +9753,7 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt,
}
}
if (ret == 0) {
- node->_private = define;
+ node->psvi = define;
}
ctxt->flags = oldflags;
ctxt->state = oldstate;
diff --git a/testSAX.c b/testSAX.c
index 4f00c53e..538c8d7a 100644
--- a/testSAX.c
+++ b/testSAX.c
@@ -8,6 +8,13 @@
#include "libxml.h"
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
#ifdef LIBXML_SAX1_ENABLED
#include <string.h>
#include <stdarg.h>
@@ -51,7 +58,145 @@ static int nonull = 0;
static int sax2 = 0;
static int repeat = 0;
static int callbacks = 0;
+static int timing = 0;
+
+/*
+ * Timing routines.
+ */
+/*
+ * Internal timing routines to remove the necessity to have unix-specific
+ * function calls
+ */
+
+#ifndef HAVE_GETTIMEOFDAY
+#ifdef HAVE_SYS_TIMEB_H
+#ifdef HAVE_SYS_TIME_H
+#ifdef HAVE_FTIME
+
+static int
+my_gettimeofday(struct timeval *tvp, void *tzp)
+{
+ struct timeb timebuffer;
+
+ ftime(&timebuffer);
+ if (tvp) {
+ tvp->tv_sec = timebuffer.time;
+ tvp->tv_usec = timebuffer.millitm * 1000L;
+ }
+ return (0);
+}
+#define HAVE_GETTIMEOFDAY 1
+#define gettimeofday my_gettimeofday
+
+#endif /* HAVE_FTIME */
+#endif /* HAVE_SYS_TIME_H */
+#endif /* HAVE_SYS_TIMEB_H */
+#endif /* !HAVE_GETTIMEOFDAY */
+
+#if defined(HAVE_GETTIMEOFDAY)
+static struct timeval begin, end;
+/*
+ * startTimer: call where you want to start timing
+ */
+static void
+startTimer(void)
+{
+ gettimeofday(&begin, NULL);
+}
+
+/*
+ * endTimer: call where you want to stop timing and to print out a
+ * message about the timing performed; format is a printf
+ * type argument
+ */
+static void
+endTimer(const char *fmt, ...)
+{
+ long msec;
+ va_list ap;
+
+ gettimeofday(&end, NULL);
+ msec = end.tv_sec - begin.tv_sec;
+ msec *= 1000;
+ msec += (end.tv_usec - begin.tv_usec) / 1000;
+
+#ifndef HAVE_STDARG_H
+#error "endTimer required stdarg functions"
+#endif
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+
+ fprintf(stderr, " took %ld ms\n", msec);
+}
+#elif defined(HAVE_TIME_H)
+/*
+ * No gettimeofday function, so we have to make do with calling clock.
+ * This is obviously less accurate, but there's little we can do about
+ * that.
+ */
+#ifndef CLOCKS_PER_SEC
+#define CLOCKS_PER_SEC 100
+#endif
+
+static clock_t begin, end;
+static void
+startTimer(void)
+{
+ begin = clock();
+}
+static void
+endTimer(const char *fmt, ...)
+{
+ long msec;
+ va_list ap;
+
+ end = clock();
+ msec = ((end - begin) * 1000) / CLOCKS_PER_SEC;
+
+#ifndef HAVE_STDARG_H
+#error "endTimer required stdarg functions"
+#endif
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ fprintf(stderr, " took %ld ms\n", msec);
+}
+#else
+
+/*
+ * We don't have a gettimeofday or time.h, so we just don't do timing
+ */
+static void
+startTimer(void)
+{
+ /*
+ * Do nothing
+ */
+}
+static void
+endTimer(char *format, ...)
+{
+ /*
+ * We cannot do anything because we don't have a timing function
+ */
+#ifdef HAVE_STDARG_H
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+ fprintf(stderr, " was not timed\n", msec);
+#else
+ /* We don't have gettimeofday, time or stdarg.h, what crazy world is
+ * this ?!
+ */
+#endif
+}
+#endif
+
+/*
+ * empty SAX block
+ */
xmlSAXHandler emptySAXHandlerStruct = {
NULL, /* internalSubset */
NULL, /* isStandalone */
@@ -968,7 +1113,12 @@ int main(int argc, char **argv) {
else if ((!strcmp(argv[i], "-speed")) ||
(!strcmp(argv[i], "--speed")))
speed++;
- else if ((!strcmp(argv[i], "-repeat")) ||
+ else if ((!strcmp(argv[i], "-timing")) ||
+ (!strcmp(argv[i], "--timing"))) {
+ nonull++;
+ timing++;
+ quiet++;
+ } else if ((!strcmp(argv[i], "-repeat")) ||
(!strcmp(argv[i], "--repeat"))) {
repeat++;
quiet++;
@@ -988,7 +1138,13 @@ int main(int argc, char **argv) {
if (noent != 0) xmlSubstituteEntitiesDefault(1);
for (i = 1; i < argc ; i++) {
if (argv[i][0] != '-') {
+ if (timing) {
+ startTimer();
+ }
parseAndPrintFile(argv[i]);
+ if (timing) {
+ endTimer("Parsing");
+ }
files ++;
}
}