Friday, February 12, 2010

In my earlier blog I had summarized from experience and material on the web that was born out by my own observations. I decided to construct a very simple demo program as shown at the bottom of this blog. I loaded the same file with each approach and counted the nodes in a Xml file. The box was quad-x64 core with 12 Gigs of ram.

The results are very information for guidance.

x86

Memory (K)

Msec

Memory Delta

No Op

3196

1.95

XmlDocument

43912

1221.70

40716

XDocument

34700

836.90

31504

XmlReader

3696

299.80

500

x64

Memory (K)

Msec

Memory Delta

No Op

3184

0.98

XmlDocument

74900

1076.20

71716

XDocument

48252

782.23

45068

XmlReader

5280

301.76

2096

First, as expected x64 was faster by about 20% – not a huge amount. What was very interesting is that the memory consumption – from 43% more to 319% more; in other words a web application that uses XML heavy that runs in 3Gigs of memory if compiled as x86 could require 12Gigs of memory if compiled as x64 for perhaps a 20% increase of performance. It makes more sense to run two instances of the web site compiled as x86 and double the performance using only 6 Gigs of memory.

As expected, XmlReader was the best performing:

A 3 Gig Xml-Heavy web application using XmlDocument would run THREE times faster using only 100 megs of memory in X64 --- yes, 1/35 of the memory needs. In x86, it’s more shocking: only 36 megs of memory would be needed!

For XDocument, the magnitude is not as severe, but still a magnitude different!

If you wish to try the code, here is the Console app code. The memory used is obtained by looking at Task Manager(I did not clean up objects intentionally so task manager would show the peak memory).