G
Guest
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
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