有多大的XPathNavigator和的XmlReader之间的速度差,真的吗? [英] How big is the speed difference between XPathNavigator and XmlReader, really?

查看:136
本文介绍了有多大的XPathNavigator和的XmlReader之间的速度差,真的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我需要解析为一个.NET类结构相当大的XML文件(映射到一个固定长度的记录格式,并通过MQ传输)。性能是很重要的,但不是绝对关键的。

I've got a fairly big XML file that I need to parse into a .NET class structure (to be mapped to a fixed-length record format and transmitted via MQ). Performance is important, but not absolutely critical.

我几乎总是使用的XPathNavigator 来读取XML文件,因为它比的XmlReader 更容易。在另一方面,我知道的XmlReader 的XPathNavigator 更快,因为它在理论上只是一次读取的,而一个节点的XPathNavigator 必须读取足够的执行XPath,可能是整个文档。

I almost always use XPathNavigator to read XML files because it's much easier than XmlReader. On the other hand, I know XmlReader is faster than XPathNavigator, because it theoretically just reads one node at a time whereas XPathNavigator has to read enough to execute an XPath, possibly the whole document.

我的问题是:如何更快真的是这样吗?阅读几千节点时,它会做出一个明显的区别?什么是临界点在哪里pretty的很多都改用的XmlReader ?或者是的XPathNavigator 优化到如此地步,它总是一个好的选择?

My question is: how much faster is it really? Will it make a noticeable difference when reading a few thousand nodes? What's the tipping point where I pretty much have to switch to XmlReader? Or is XPathNavigator optimized to the point that it's always a good option?

我的大部分XML的经验是在相对较小的文件,所以我希望从任何人输入谁是大文件的工作。

Most of my XML experience is on relatively small files, so I'm looking for input from anybody who's worked with big files.

推荐答案

据我所知唯一的地方,你可以得到的XPathNavigator的实现无论从.Xml.Linq.XDocument或XPathDocument的两个它在内存中保存整个树。

As far as I'm aware the only places where you can get an implementation of XPathNavigator is from either the .Xml.Linq.XDocument or the XPathDocument both of which hold the entire tree in memory.

另一方面的XmlReader的可以检索并解析XML流,而不需要收集一组节点成树

The XmlReader on the other hand can retrieve and parse a stream of XML without the need to collect a set of nodes into a tree.

因此​​,假设你收集你的所有必需数据,仅正向的方式,那么对于大型数据集的XmlReader应了简单的基础上执行的XPathNavigator是: -

Hence assuming you gather all your required data in a forward only manner, then for large data sets XmlReader should out perform XPathNavigator simply on the basis that:-

  1. 您将不得不deserialise XML流反正来填充文件和
  2. 您就不必装入一个大的项目集到内存中。

这篇关于有多大的XPathNavigator和的XmlReader之间的速度差,真的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆