Would anyone enlighten me some comprehensive performance comparison between XPath and DOM in different scenarios? I've read some questions in SO like xPath vs DOM API, which one has a better performance and XPath or querySelector?. None of them mentions specific cases. Here's somethings I could start with.
- No iteration involved. getElementById(foobar) vs //*[@id='foobar']. Is former constantly faster than latter? What if the latter is optimized, e.g. /html/body/div[@id='foo']/div[@id='foobar']?
- Iteration involved. getElementByX then traverse through child nodes vs XPath generate snapshot then traverse through snapshot items.
- Axis involved. getElementByX then traverse for next siblings vs //following-sibling::foobar.
- Different implementations. Different browsers and libraries implement XPath and DOM differently. Which browser's implementation of XPath is better?
As the answer in xPath vs DOM API, which one has a better performance says, average programmer may screw up when implementing complicated tasks (e.g. multiple axes involved) in DOM way while XPath is guaranteed optimized. Therefore, my question only cares about the simple selections that can be done in both ways.
Thanks for any comment.