| re: odd performance question - xml parsing
doc.load(filename) - creates a validating xml reader, which is why its so
slow
new XmlTextReader(filename) - expects a uri, not a filename. if no protocol
is specified, then its converted to a file based uri (file://filename), then
opened as a uri resource. this transalation requires serveral directory
lookups.
new XmlTextReader(reader) - just read the stream of bytes from the reader.
if you pick one optimized for file opening and reading, its fastest.
-- bruce (sqlwork.com)
"Mark" <mmodrall@nospam.nospam> wrote in message
news:342C8154-A4A9-4088-80DE-DDAA9956BA7C@microsoft.com...[color=blue]
> Hi...
>
> We've been doing some basic performance testing comparing asp, asp.net,
> mono, and php. One of the basic tests is on simply parsing an xml
> document
> and streaming the result back to the client.
>
> I never would have thought of it, but someone in our group had heard that
> using XmlDocument.Load (Server.MapPath (file));
> was slower than actually creating the stream, the XmlTextReader, and
> passing
> the reader to the XmlDocument.Load();.
>
> I've tried it, and darn if he wasn't right.
>
> System.Xml.XmlDocument DOMObj = new System.Xml.XmlDocument();
> System.IO.StreamReader stream = new System.IO.StreamReader
> (Server.MapPath("file.xml"));
> System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(stream);
> reader.WhitespaceHandling = System.Xml.WhitespaceHandling.None;
> DOMObj.Load(reader);
>
> was 5% faster than
>
> System.Xml.XmlDocument DOMObj = new System.Xml.XmlDocument();
> System.Xml.XmlTextReader reader = new
> System.Xml.XmlTextReader(Server.MapPath ("file.xml"));
> reader.WhitespaceHandling = System.Xml.WhitespaceHandling.None;
> DOMObj.Load(reader);
>
> which was 20% faster than
> System.Xml.XmlDocument DOMObj = new System.Xml.XmlDocument();
> DOMObj.PreserveWhitespace = true;
> DOMObj.Load(Server.MapPath("file.xml"));
>
> I can't think of any reason why it's so much faster to manually create
> your
> own stream and XmlTextReader rather than letting XmlDocument figure out
> the
> fastest way to process the document.
>
> Any ideas?
>
> Thanks
> _mark
>[/color] |