xsl-list
[Top] [All Lists]

Re: [xsl] Using memory addressing to retrieve a value vice using a software string library to retrieve a value

2015-11-20 06:28:16
Measure it and see. It depends totally on which XPath engine you are using. 
Many simple XPath engines are likely to search the child elements of <edge> 
sequentially, and to use string comparison to compare the name of each element 
with "west". Others may index the children by element name, or may optimize the 
name comparison.

You'll probably have to scale the problem up considerably if you want the 
difference to be measurable.

Michael Kay
Saxonica


On 20 Nov 2015, at 12:13, Costello, Roger L. costello(_at_)mitre(_dot_)org 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hi Folks,

I want to retrieve "west".

Which of these is faster?

-------------------
Approach #1
-------------------
The <edge> element contains text:

      <edge>garden west door</edge>

"west" is retrieved using this XPath:

      substring-before(substring-after(., ' '), ' ')

Note: assume that <edge> is the context node.

-------------------
Approach #2
-------------------
The <edge> element contains markup:

      <edge>
          <garden/>
          <west/>
          <door/>
      </edge>

"west" is retrieved using this XPath:

      *[2]/name()


I believe that Approach #2 is much, much faster. Do you agree? 

As I see it, Approach #2 is simply a memory addressing task (which computers 
do very well) to obtain <west/> and then output the symbols at that memory 
address. Approach #1, on the other hand, requires the use of software string 
libraries, which, I imagine, results in hundreds or thousands of machine 
instructions. In fact, I would imagine that Approach #2 is hundreds or 
thousands of times faster than Approach #1. Do you agree?

/Roger

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>