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")
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")
is the equivalent of your first statement.
There will be a performance difference, because the methods are doing different things. However, it will be so miniscule that you don't need to worry about it most of the time.
EDIT: I have no evidence for the above assertion, I'm just going on the principle that optimising 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.
Yes there will be although the two lines aren't equivalent.
The XPath needs to be parsed ultimately into a LINQ expression which would then do this:-
var x = document.Elements("actors").Elements("actor");
However its quite possible that internally a compiled version of the XPath expression is stored so that using an XPath only costs the time it takes to look up the string in some internally held dictionary. Whether that is actually the case or not I don't know.