Damon Armstrong

Caffeine Induced Tirades about .NET and Life
And don't forget to check out my latest Simple-Talk articles
Add to Technorati Favorites      Add to Google     

Performance: Caching vs. Reading from an In-Memory XML Document

Published Wednesday, August 22, 2007 1:01 AM

I've been working with a number of XML documents recently.  Basically I'm trying to expose configuration values stored in XML configuration files in an object-oriented structure.  I'm using an in-memory XML document and just referencing values as needed from that document.  The XML reading does not need to be super-high performance because it does not occur very often, but it got me to thinking... what if it did?

So I ran some performance tests to check the difference between accessing a value from an XML document vs. storing the value in cache and accessing it through a standard get property. 

The results (at least on my machine) are as follows:

 

Iterations / Millisecond

Performance Difference
XML (attribute value)

8,648

90% slower

XML (inner text value)

21,694

76% slower

Cached Property

90,140

 

I knew caching would beat out the other two methods since it's very fast to access a direct variable, but I was surprised that there was such a difference.  I figured there would be a bit of overhead for the inner text property, and a bit more for the attribute lookup, but I was thinking it would be in the range of 10-20% slower.  Live and learn.  Of course, reading from an in-memory XML document is still pretty dang fast, it's just that reading from a cached value is faster.

by Damon

Comments

 

strazz said:

I've always wondered this and never gotten around to testing.  Thanks for a simple article that gets the point across.  If you aren't too busy, I'd be curious to know how you actually got the results.
August 22, 2007 4:16 PM
 

Jason Haley said:

August 23, 2007 9:14 AM
 

Damon said:

Unfortunately, I tossed the code when I was finished.  I will, however, make another post showing how I do performance testing.  It's fairly unscientific, but it works well enough to give you a rough idea of how well things perform.
August 24, 2007 2:39 PM
 

7610 download mobile nokia theme said:

7610 download mobile nokia theme
November 7, 2007 4:12 AM
You need to sign in to comment on this blog

















<August 2007>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678
Virtual Exchange Servers
 Microsoft now supports running Exchange Server 2007 in server virtualization environments, not just on... Read more...

Virtualizing Exchange: points for discussion
 With the increasing acceptance of the use of Virtualization as a means of providing server... Read more...

Encouraging .NET Reflector Add-ins
 Jason Haley is well-known for the resources he's provided to developers who wish to extend Reflector's... Read more...

Using .NET Reflector Add-ins
 .NET Reflector by itself is great, but it really comes into its own with the help of some add-ins. Here... Read more...

Unique Experiences!
 You'd have thought that a unique constraint was an easy concept - Not a bit of it; it can cause a lot... Read more...