本文介绍了XPathSelectElement VS后裔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在想,如果使用的简单查询,当有任何性能差异:
VAR X = document.XPathSelectElement(演员/演员)
对
变种X = document.Descendants(演员)。后代(男主角)
解决方案
请注意,此
VAR X = document.Elements(演员)元素(男主角)FirstOrDefault()。
是您的第一条语句是等效的。
有将是一个性能差,因为该方法在引擎盖下做的非常不同的事情。但是,纯粹的优化内存的操作是有点毫无意义,除非你是在处理大型数据集。如果你正在处理大型数据集,则应当同时测量方案的性能,而不是试图预测哪些人会跑得更快。
I was wondering if there are any performance differences when using simple queries as:
var x = document.XPathSelectElement("actors/actor")
vs
var x = document.Descendants("actors").Descendants("actor")
解决方案
Note that this
var x = document.Elements("actors").Elements("actor").FirstOrDefault();
is the equivalent of your first statement.
There will be a performance difference, because the methods are doing very different things under the hood. However, optimising purely in-memory operations is a bit pointless unless you are dealing with a large data set. If you are dealing with a large data set, then you should measure the performance of both alternatives rather than trying to predict which one will run faster.
这篇关于XPathSelectElement VS后裔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!