性能:XmlReader的或LINQ到XML性能、XmlReader、XML、LINQ

2023-09-04 01:48:25 作者:太阳好冷

我有被用作数据库在我的项目一个150 MB的XML文件。目前我使用的XmlReader 来读取它的内容。我想知道这是否是最好使用的XmlReader 或LINQ到XML对于这种情况。

I have a 150 MB XML file which is used as DB in my project. Currently I'm using XmlReader to read content from it. I want to know if it is better to use XmlReader or LINQ to XML for this scenario.

请注意,我在寻找这个XML和显示搜索结果中的项目,因此它可能需要很长的时间,或只是一瞬间。

Note that I'm searching for an item in this XML and display search result, so it can take a long time or just a moment.

推荐答案

。它不读取整个文件,并在内存中建立DOM树。相反,它,从磁盘读取该文件,并给你回发现在路上的每个节点。

If you want performance use XMLReader. It doesn't read the whole file and build the DOM tree in memory. It instead, reads the file from disk and gives you back each node it finds on the way.

通过一个快速谷歌搜索,我发现的XMLReader,LinqToXML和XDocument.Load的性能对比。

With a quick google search I found a performance comparison of XMLReader, LinqToXML and XDocument.Load.

http://www.nearinfinity.com/blogs/joe_ferner/performance_linq_to_sql_vs.html