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
On the Trail of the Expanding Databases
 It is sometimes difficult for other IT people to understand the constraints that DBAs have to work... Read more...

SQL Server 2008: The New Data Types
 Brad continues his helicopter-level view of the most interesting new features of SQL Server 2008 with a... Read more...

Reporting on Mobile Device Activity Using Exchange 2007 ActiveSync Logs
 In this new column giving practical advice on all things Sys Admin related, Ben Lye takes on the often... Read more...

The Bejeweled Puzzle in SQL
 Alex Kozak provides another SQL puzzle to hone your SQL Skills with.  Read more...

Using Powershell to Generate Table-Creation Scripts
 For all of us who learn best by trying out examples, Bob Sheldon produces a PowerShell script file for... Read more...