Re: [xml] xmlDocDumpMemory() is VERY slow on Win32

I've just discovered something else very strange going on, which enables 
me to present a small self-contained test case.

Previously, I could only reproduce the slowness with a particular XML 
file that I was working with.  Whenever I tried to have the test program 
create an XML file itself for the purposes of testing, the speed 
difference did not show up.

The XML file that I was working with declared the encoding to be 
"iso-8859-1", but I was omitting the encoding declaration in the test 
XML files that I was creating.  It turns out that this also affects things!

The following program:

#include <stdio.h>
#include <time.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
int main(void) {
  char *file = "foo.xml";
  char *line = "..................................................\n";
  char *encodings[] = { "encoding=\"iso-8859-1\"", "encoding=\"utf-8\"", 
"" };
  FILE *f;
  time_t start, end;
  xmlDocPtr doc;
  xmlChar *result;
  int i, j, len = 0;
  for (i = 0; i < 3; i++) {
    if ((f = fopen(file, "w")) == NULL) {
      printf("can't write test file!\n");
      return 3;
    fprintf(f, "<?xml version=\"1.0\" %s?>\n", encodings[i]);
    fprintf(f, "<test><![CDATA[\n");
    for (j = 0; j < 200000; j++) {
      fprintf(f, line);
    fprintf(f, "]]></test>\n");
    if ((doc = xmlReadFile(file, NULL, 0)) == NULL) {
      printf("can't read test file!\n");
      return 4;
    xmlDocDumpMemory(doc, &result, &len);
    if (result == NULL) {
      printf("can't dump test file!\n");
      return 5;
    printf("%s: %d seconds\n", encodings[i], end - start);
  return 0;

generates these bizarre results for me on Win32:

encoding="iso-8859-1": 15 seconds
encoding="utf-8": 15 seconds
: 0 seconds

Why is xmlDocDumpMemory() so much slower when an encoding is declared?

This is using libxml2-2.6.11 built with MSVC++ 6.0 the same way as 
described in my original posting.

What results does the program produce on Linux?

Does this help anyone help me with this problem?

- Steve

Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for 
the addressee(s) only.  If you have received this message in error or there are any problems, please notify 
the sender immediately.  The unauthorized use, disclosure, copying or alteration of this message is strictly 
forbidden.  Note that any views or opinions presented in this email are solely those of the author and do not 
necessarily represent those of Radan Computational Ltd.  The recipient(s) of this message should check it and 
any attached files for viruses: Radan Computational will accept no liability for any damage caused by any 
virus transmitted by this email.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]