*** xmllint/orig Wed Dec 5 03:35:06 2001 --- xmllint/riscos Mon Dec 17 09:56:19 2001 *************** *** 20,26 **** --- 20,31 ---- #include #endif /* _MSC_VER */ #else /* _WIN32 */ + #ifdef HAVE_SYS_TIME_H #include + #endif + #ifdef HAVE_TIME_H + #include + #endif #endif /* _WIN32 */ *************** *** 110,121 **** static int progresult = 0; static int timing = 0; static int generate = 0; - static struct timeval begin, end; #ifdef LIBXML_CATALOG_ENABLED static int catalogs = 0; static int nocatalogs = 0; #endif /************************************************************************ * * * HTML ouput * --- 115,220 ---- static int progresult = 0; static int timing = 0; static int generate = 0; #ifdef LIBXML_CATALOG_ENABLED static int catalogs = 0; static int nocatalogs = 0; #endif + /* + * Internal timing routines to remove the necessity to have unix-specific + * function calls + */ + + #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 *format, ...) + { + 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, format); + vfprintf(stderr,format,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. + */ + + static clock_t begin, end; + static void startTimer(void) + { + begin=clock(); + } + static void endTimer(char *format, ...) + { + 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, format); + vfprintf(stderr,format,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 + + /************************************************************************ * * * HTML ouput * *************** *** 405,411 **** xmlDocPtr doc = NULL, tmp; if ((timing) && (!repeat)) ! gettimeofday(&begin, NULL); if (filename == NULL) { --- 504,510 ---- xmlDocPtr doc = NULL, tmp; if ((timing) && (!repeat)) ! startTimer(); if (filename == NULL) { *************** *** 591,617 **** } if ((timing) && (!repeat)) { ! long msec; ! gettimeofday(&end, NULL); ! msec = end.tv_sec - begin.tv_sec; ! msec *= 1000; ! msec += (end.tv_usec - begin.tv_usec) / 1000; ! fprintf(stderr, "Parsing took %ld ms\n", msec); } #ifdef LIBXML_XINCLUDE_ENABLED if (xinclude) { if ((timing) && (!repeat)) { ! gettimeofday(&begin, NULL); } xmlXIncludeProcess(doc); if ((timing) && (!repeat)) { ! long msec; ! gettimeofday(&end, NULL); ! msec = end.tv_sec - begin.tv_sec; ! msec *= 1000; ! msec += (end.tv_usec - begin.tv_usec) / 1000; ! fprintf(stderr, "Xinclude processing took %ld ms\n", msec); } } #endif --- 690,706 ---- } if ((timing) && (!repeat)) { ! endTimer("Parsing"); } #ifdef LIBXML_XINCLUDE_ENABLED if (xinclude) { if ((timing) && (!repeat)) { ! startTimer(); } xmlXIncludeProcess(doc); if ((timing) && (!repeat)) { ! endTimer("Xinclude processing"); } } #endif *************** *** 664,670 **** if (!debug) { #endif if ((timing) && (!repeat)) { ! gettimeofday(&begin, NULL); } #ifdef HAVE_SYS_MMAN_H if (memory) { --- 753,759 ---- if (!debug) { #endif if ((timing) && (!repeat)) { ! startTimer(); } #ifdef HAVE_SYS_MMAN_H if (memory) { *************** *** 706,717 **** else xmlDocDump(stdout, doc); if ((timing) && (!repeat)) { ! long msec; ! gettimeofday(&end, NULL); ! msec = end.tv_sec - begin.tv_sec; ! msec *= 1000; ! msec += (end.tv_usec - begin.tv_usec) / 1000; ! fprintf(stderr, "Saving took %ld ms\n", msec); } #ifdef LIBXML_DEBUG_ENABLED } else { --- 795,801 ---- else xmlDocDump(stdout, doc); if ((timing) && (!repeat)) { ! endTimer("Saving"); } #ifdef LIBXML_DEBUG_ENABLED } else { *************** *** 727,742 **** xmlDtdPtr dtd; if ((timing) && (!repeat)) { ! gettimeofday(&begin, NULL); } dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid); if ((timing) && (!repeat)) { ! long msec; ! gettimeofday(&end, NULL); ! msec = end.tv_sec - begin.tv_sec; ! msec *= 1000; ! msec += (end.tv_usec - begin.tv_usec) / 1000; ! fprintf(stderr, "Parsing DTD took %ld ms\n", msec); } if (dtd == NULL) { xmlGenericError(xmlGenericErrorContext, --- 811,821 ---- xmlDtdPtr dtd; if ((timing) && (!repeat)) { ! startTimer(); } dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid); if ((timing) && (!repeat)) { ! endTimer("Parsing DTD"); } if (dtd == NULL) { xmlGenericError(xmlGenericErrorContext, *************** *** 745,753 **** } else { xmlValidCtxt cvp; if ((timing) && (!repeat)) { ! gettimeofday(&begin, NULL); } ! cvp.userData = (void *) stderr; cvp.error = (xmlValidityErrorFunc) fprintf; cvp.warning = (xmlValidityWarningFunc) fprintf; if (!xmlValidateDtd(&cvp, doc, dtd)) { xmlGenericError(xmlGenericErrorContext, "Document %s does not validate against %s\n", --- 824,834 ---- } else { xmlValidCtxt cvp; if ((timing) && (!repeat)) { ! startTimer(); } ! cvp.userData = (void *) stderr; ! cvp.error = (xmlValidityErrorFunc) fprintf; ! cvp.warning = (xmlValidityWarningFunc) fprintf; if (!xmlValidateDtd(&cvp, doc, dtd)) { xmlGenericError(xmlGenericErrorContext, "Document %s does not validate against %s\n", *************** *** 755,773 **** progresult = 3; } if ((timing) && (!repeat)) { ! long msec; ! gettimeofday(&end, NULL); ! msec = end.tv_sec - begin.tv_sec; ! msec *= 1000; ! msec += (end.tv_usec - begin.tv_usec) / 1000; ! fprintf(stderr, "Validating against DTD took %ld ms\n", msec); } xmlFreeDtd(dtd); } } else if (postvalid) { xmlValidCtxt cvp; if ((timing) && (!repeat)) { ! gettimeofday(&begin, NULL); } cvp.userData = (void *) stderr; cvp.error = (xmlValidityErrorFunc) fprintf; --- 836,849 ---- progresult = 3; } if ((timing) && (!repeat)) { ! endTimer("Validating against DTD"); } xmlFreeDtd(dtd); } } else if (postvalid) { xmlValidCtxt cvp; if ((timing) && (!repeat)) { ! startTimer(); } cvp.userData = (void *) stderr; cvp.error = (xmlValidityErrorFunc) fprintf; *************** *** 778,789 **** progresult = 3; } if ((timing) && (!repeat)) { ! long msec; ! gettimeofday(&end, NULL); ! msec = end.tv_sec - begin.tv_sec; ! msec *= 1000; ! msec += (end.tv_usec - begin.tv_usec) / 1000; ! fprintf(stderr, "Validating took %ld ms\n", msec); } } --- 854,860 ---- progresult = 3; } if ((timing) && (!repeat)) { ! endTimer("Validating"); } } *************** *** 796,811 **** * free it. */ if ((timing) && (!repeat)) { ! gettimeofday(&begin, NULL); } xmlFreeDoc(doc); if ((timing) && (!repeat)) { ! long msec; ! gettimeofday(&end, NULL); ! msec = end.tv_sec - begin.tv_sec; ! msec *= 1000; ! msec += (end.tv_usec - begin.tv_usec) / 1000; ! fprintf(stderr, "Freeing took %ld ms\n", msec); } } --- 867,877 ---- * free it. */ if ((timing) && (!repeat)) { ! startTimer(); } xmlFreeDoc(doc); if ((timing) && (!repeat)) { ! endTimer("Freeing"); } } *************** *** 1073,1079 **** continue; } if ((timing) && (repeat)) ! gettimeofday(&begin, NULL); /* Remember file names. "-" means stding. */ if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) { if (repeat) { --- 1139,1145 ---- continue; } if ((timing) && (repeat)) ! startTimer(); /* Remember file names. "-" means stding. */ if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) { if (repeat) { *************** *** 1083,1094 **** parseAndPrintFile(argv[i]); files ++; if ((timing) && (repeat)) { ! long msec; ! gettimeofday(&end, NULL); ! msec = end.tv_sec - begin.tv_sec; ! msec *= 1000; ! msec += (end.tv_usec - begin.tv_usec) / 1000; ! fprintf(stderr, "100 iterations took %ld ms\n", msec); } } } --- 1149,1155 ---- parseAndPrintFile(argv[i]); files ++; if ((timing) && (repeat)) { ! endTimer("100 iterations"); } } }