in reply to my xml xpath is too slow.

The first suggestion that comes to my mind is to ditch XML::XPath and replace it with XML::LibXML. That will speedup your code, and you will be using a module that is actually maintained.

Then of course the //pair[@id = '.$n.'] is a big red flag. Especially as you seem to be doing this twice for each $n (it's hard to tell as your code is not indented). Either try to have the complete path above pair, or do the search on //pair only once, cache the results in a hash id => node and use this in the rest of your code. Does this make sense?

Replies are listed 'Best First'.
Re^2: my xml xpath is too slow.
by Anonymous Monk on Aug 26, 2009 at 09:38 UTC
    Thanks for reply, I never used LibXML, do you think it would work faster? I have to say with the full path for //pair ( /e-c/pair instead of //pair), it did not help for speed. Moreover since it's pair I have to extract it in to different process, as it is in my code.

      XML::LibXML would certainly run much faster, XML::XPath is quite slow. and the code would be very similar. I am surprised that removing the // did not speed up the code though.