【发布时间】:2011-12-10 07:28:28
【问题描述】:
有谁知道哪个更高效/更快。什么是我自己测试的好方法,我没有大型 XML 文档(
XDocument doc = XDocument.Load(file);
doc.Root.Element("childNode").Value;
或
doc.Element("rootNode").Element("childNode").Value ;
另一个:
doc.Root.Elements("childNodes");
对比
doc.Element("rootNode).Elements("childNodes");
对比
doc.Element("rootNode").Descendants("childNodes");
对比
doc.Root.Descendants("childNodes") ;
比较时:
doc.XPathSelectElement("/xpath").Value
它是否比 DOM 方法更快,即
XMLDocument dom = new XMLDocument();
dom.LoadXml(input);
dom.SelectSingleNode("/xpath").Value
【问题讨论】:
-
您是否尝试过对它们进行基准测试?
-
几乎不可能有人已经知道这个答案。自己测试一下吧!此外,后代与元素的性能高度依赖于 XML 文档的结构
标签: linq performance linq-to-xml