
On Fri, 2009-10-23 at 11:49 +0200, Stefan Behnel wrote:
I expect this is properly a libxml2 question, but it's weird enough I wanted to check here first to make sure that lxml isn't effecting the results.
I have equivalent XPath expressions, one using prefixes to do the selection, and one using namespace-uri to do the check. The namespace-uri version consistently runs 2-3x faster on a range of test data, and I have no idea why.
Here's the prefix version:
'//@gizmo:*/parent::*[ not( self::gizmo:* ) ]'
And here's the namespace-uri version:
'//@*[ namespace-uri( ) = "%(gizmo)s" ]/parent::*[ namespace-uri( ) != "%(gizmo)s" ]' % namespaces <snipped> BTW, have you also measured the performance of using an XPath variable for
John Krukoff wrote: the URI in the second case?
Stefan
Finally got around to giving this a try, and the performance difference for using XPath variables looks to be negligible. Switched over to using variables then, as the substitution is obviously safer in the general case, and it looks a bit cleaner. Wanted to mention on the list, in case anybody else ends up using this optimization. As always, thanks for the tip Stefan. -- John Krukoff <jkrukoff@ltgc.com> Land Title Guarantee Company