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
Niklaus Wirth: Geek of the Week
 It is difficult to begin to estimate the huge extent of the contribution that Niklaus Wirth has made to... Read more...

Building an Exchange Server 2007 environment
 Of course, changing a 32,000 mailbox system, based in 40 Exchange Servers, to a centralised 25,000... Read more...

Manage Stress Before it Kills You
 The key to a long career in IT is in learning how to cope adaptively with stress. Matt Simmons, like... Read more...

Expecting the Worst
 Optimists are often disappointed Read more...

To Boldly Ask IT for Development Work
 Phil has always been mystified by the way that, in Science-Fiction films, the crew of space-ships are... Read more...