Altova Mailing List Archives


Re: selectSingleNode VS selectNodes : Which is faster ?

From: "Raoul Borges" <paercebal@-------.--->
To: NULL
Date: 6/20/2006 5:20:00 PM

You're right, but I'm still surprised:

I searched again, and found this URL:
http://msdn.microsoft.com/msdnmag/issues/03/07/XPathandXSLT/
Where the same author explains it a little more

===================================================
|
|   The SelectSingleNode method works as a special case of SelectNodes
|   in that it returns only the first element of the returned node-set.
|   Unfortunately, up until now, the implementation of SelectSingleNode has
|   not been particularly efficient. If you need to locate only the first matching
|   node, then calling SelectSingleNode or SelectNodes is nearly identical.
|   Moreover, if you need to squeeze out every little bit of performance,
|   you're probably better off using SelectNodes.
|
===================================================

I would have disagreed with the following...

===================================================
|
|   This is an XPath best practice in general and is not due to the .NET
|   Framework implementation in particular.
|
===================================================

.... because my own test with MSXML4 (not .NET) show that a selectNodes
is at least 2 times slower than a selectSingleNode, and that adding a
"[position() = 1]" postffix to a XPath string will slow a selectSingleNode and
a selectNodes by 15%

But then, I went to Apache, and looked at the Xalan's implementation of
selectSingleNode and selectNodeList, and found a similar code:
 XPathEvaluator.cpp (line 93 and 177)

==================================================
|
|   XalanNode* XPathEvaluator::selectSingleNode(...)
|   {
|    const XObjectPtr theResult(...);
|
|    const NodeRefListBase& theNodeList = theResult->nodeset();
|
|    return theNodeList.getLength() == 0 ? 0 : theNodeList.item(0);
|   }
==================================================
|
|   NodeRefList& XPathEvaluator::selectNodeList(...)
|   {
|    const XObjectPtr theResult(...);
|
|    result = (theResult->nodeset());
|
|       return result;
|   }
|
==================================================

Which shows a code similar to the pseudo-code shown by the .NET example.

There must be a core difference between MSXML 4 and other DOM
implemantions...

: /

Thanks, anyway...
: )


-- Raoul BORGES


"Bjoern Hoehrmann" <bjoern@h...> a écrit dans le message de news:
dcmf9291q9o06481m5p10tc9gpqhf1a776@h......
> * Raoul Borges wrote in microsoft.public.xml:
> >http://www.devx.com/vb2themax/Tip/18823
>
> >Could I have some external advice about all this ?
> >(if from someone familiar with internal workings of the MSXML, all the better !)
>
> The article is apparently based on an implementation detail of the
> methods in the .NET Framework 1.0; if SelectSingleNode is indeed im-
> plemented as the article states, the conclusions are reasonable (if
> you assume there is no lazy evaluation). It does not say anything
> about other versions of the Framework or MSXML.
> --
> Björn Höhrmann · mailto:bjoern@h... · http://bjoern.hoehrmann.de
> Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
> 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/


Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.