<p>I need to know how the performance of different XML tools (parsers, validators, XPath expression evaluators, etc) is affected by the size and complexity of the input document. Are there resources out there that document how CPU time and memory usage are affected by... well, what? Document size in bytes? Number of nodes? And is the relationship linear, polynomial, or worse?</p>

<p><strong>Update</strong></p>

<p>In an article in IEEE Computer Magazine, vol 41 nr 9, sept 2008, the authors survey four popular XML parsing models (DOM, SAX, StAX and VTD). They run some very basic performance tests which show that a DOM-parser will have its throughput halved when the input file's size is increased from 1-15 KB to 1-15 MB, or about 1000x larger. The throughput of the other models is not significantly affected.</p>

<p>Unfortunately they did not perform more detailed studies, such as of throughput/memory usage as a function of number of nodes/size.</p>

<p>The article is <a href="https://www.computer.org/10.1109/MC.2008.403" rel="nofollow noreferrer">here.</a></p>

<p><strong>Update</strong></p>

<p>I was unable to find any formal treatment of this problem. For what it's worth, I have done some experiments measuring the number of nodes in an XML document as a function of the document's size in bytes. I'm working on a warehouse management system and the XML documents are typical warehouse documents, e.g. advanced shipping notice etc.</p>

<p>The graph below shows the relationship between the size in bytes and the number of nodes (which should be proportional to the document's memory footprint under a DOM model). The different colors correspond to different kinds of documents. The scale is log/log. The black line is the best fit to the blue points. It's interesting to note that for all kinds of documents, the relationship between byte size and node size is linear, but that the coefficient of proportionality can be very different.</p>

<p>
<a href="http://www.flickr.com/photos/13583850@N00/3190749168/" rel="nofollow noreferrer" title="benchmarks-bytes_vs_nodes by david.lindelof, on Flickr"><img src="https://i.stack.imgur.com/D3yVS.jpg" width="500" height="351" alt="benchmarks-bytes_vs_nodes" /></a><br>
<sub>(source: <a href="https://farm4.static.flickr.com/3470/3190749168_c999712308.jpg" rel="nofollow noreferrer">flickr.com</a>)</sub>  </p>

<p></p>

[{'answer_id': 31841, 'author': 'svrist', 'author_id': 86, 'author_profile': 'https://Stackoverflow.com/users/86', 'pm_score': 3, 'selected': True, 'text': '<p>If I was faced with that problem and couldn\'t find anything on google I would probably try to do it my self.</p>\n\n<p>Some "back-of-an-evelope" stuff to get a feel for where it is going. But it would kinda need me to have an idea of how to do a xml parser. \nFor non algorithmical benchmarks take a look here:</p>\n\n<ul>\n<li><a href="http://www.xml.com/pub/a/Benchmark/exec.html" rel="nofollow noreferrer">http://www.xml.com/pub/a/Benchmark/exec.html</a></li>\n<li><a href="http://www.devx.com/xml/Article/16922" rel="nofollow noreferrer">http://www.devx.com/xml/Article/16922</a></li>\n<li><a href="http://xerces.apache.org/xerces2-j/faq-performance.html" rel="nofollow noreferrer">http://xerces.apache.org/xerces2-j/faq-performance.html</a></li>\n</ul>\n'}, {'answer_id': 35021, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': 1, 'selected': False, 'text': '<p>I think there are too many variables involved to come up with a simple complexity metric unless you make a lot of assumptions. </p>\n\n<p>A simple SAX style parser should be linear in terms of document size and flat for memory.</p>\n\n<p>Something like XPath would be impossible to describe in terms of just the input document since the complexity of the XPath expression plays a huge role.</p>\n\n<p>Likewise for schema validation, a large but simple schema may well be linear, whereas a smaller schema that has a much more complex structure would show worse runtime performance.</p>\n\n<p>As with most performance questions the only way to get accurate answers is to measure it and see what happens!</p>\n'}, {'answer_id': 41502, 'author': 'Hank Gay', 'author_id': 4203, 'author_profile': 'https://Stackoverflow.com/users/4203', 'pm_score': 1, 'selected': False, 'text': '<p>Rob Walker is right: the problem isn\'t specified in enough detail. Considering just parsers (and ignoring the question of whether they perform validation), there are two main flavors: tree-based—think DOM—and streaming/event-based—think <a href="http://en.wikipedia.org/wiki/SAX" rel="nofollow noreferrer">SAX</a> (push) and <a href="http://en.wikipedia.org/wiki/StAX" rel="nofollow noreferrer">StAX</a> (pull). Speaking in huge generalities, the tree-based approaches consume more memory and are slower (because you need to finish parsing the whole document), while the streaming/event-based approaches consume less memory and are faster. Tree-based parsers are generally considered easier to use, although StAX has been heralded as a huge improvement (in ease-of-use) over SAX.</p>\n'}, {'answer_id': 436293, 'author': 'lkessler', 'author_id': 30176, 'author_profile': 'https://Stackoverflow.com/users/30176', 'pm_score': 0, 'selected': False, 'text': '<p>I was planning to load extremely large XML files in my application. I asked the question here on Stack Overflow:  <a href="https://stackoverflow.com/questions/264020/fastest-possible-xml-handling-in-delphi-for-very-large-documents">Fastest Possible XML handling for very large documents</a>.</p>\n\n<p>And yes, it was the parsing part, that was the bottleneck. </p>\n\n<p>I ended up not using XML parsers at all. Instead, I parsed characters one by one as efficiently as possible optimizing for speed. This resulted in speeds of 40 MB per second on a 3 GHz Windows PC for the reading, parsing and loading of the internal data structure.</p>\n\n<p>I would be very interested in hearing how the various XML parsing modes compare to this.</p>\n'}]
['https://Stackoverflow.com/questions/31826', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1428/']