473,511 Members | 17,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

odd performance question - xml parsing

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

Jan 17 '06 #1
2 1407
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" <mm******@nospam.nospam> wrote in message
news:34**********************************@microsof t.com...
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

Jan 18 '06 #2
Thanks for the great answer, Bruce...

-Mark
Jan 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2727
by: lkrubner | last post by:
I've got a PHP application that's 2 megs in size. Of that, my guess is 200k-400k is comments. Do they impose a performance hit? I've been postponing any kind of optimization, but at some point I'll...
7
2182
by: Dennis Roberts | last post by:
I have a script to parse a dns querylog and generate some statistics. For a 750MB file a perl script using the same methods (splits) can parse the file in 3 minutes. My python script takes 25...
1
1452
by: amit | last post by:
Hello, Is there any kind of performance differences to the different ways of embedding python? PyEval_EvalCode() PyRun_SimpleFile() PyObject_CallObject() Thanks
3
6044
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
15
5527
by: Sion Arrowsmith | last post by:
I've got an established client-server application here where there is now a need to shovel huge amounts of data (structured as lists of lists) between the two, and the performance bottleneck has...
3
1622
by: Toadfather | last post by:
Hi all Existing COM ATL DLL wrapping a C++ library. Interoping from a C# application, passing a large string containng XML (5-130kb). Need to significantly improve performance of both the...
3
3836
by: rony | last post by:
Hi, I am looking for component which allows me to parse my xml file. the reason i am asking this, is because my xml files are huge it can reach as far as 1GB more or less. the time to parse such...
4
1503
by: skotapal | last post by:
Hello I manage a web based VB .net application. This application has 3 components: 1. Webapp (this calls the executibles) 2. database 3. business logic is contained in individual exe...
2
1961
by: Paul McGuire | last post by:
I just ran my pyparsing unit tests with the latest Python 2.6b1 (labeled internally as Python 2.6a3 - ???), and the current 1.5.0 version of pyparsing runs with no warnings or regressions. I was...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.