[Kde-bindings] XPath benchmarks

Ashley Winters jahqueel at yahoo.com
Sat Jun 18 22:42:00 UTC 2005


Now that I have the XML format mostly complete, I wanted to check how
slow it'd be. I have a new Athlon64 3000+.

-rw-r--r--  1 jql jql 1732005 2005-06-18 14:00 QtGui.xml

I expect the size of QtGui.xml to go up at least another meg once I get
enums in there.

With XML::LibXML loaded, the base perl memory usage:
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME
COMMAND
jql      21667  1.0  0.3  24860  8124 pts/3    S+   14:58   0:00 perl 

With QtGui.xml:
jql      21704  5.0  1.3  45100 28648 pts/3    S+   15:00   0:00 perl 

It takes 0.12 seconds to load the XML file with parse_file() from disk
cache.

I used the following script as the XPath benchmark:

#!/usr/bin/perl -w
use XML::LibXML;
use Time::HiRes qw(time);
$p = XML::LibXML->new;
$doc = $p->parse_file("QtGui.xml");
$s = time;
for(1 .. 1000) {
    # lookup resize$$ in QWidget
    $doc->findnodes(
q{
 /lib
  /type[@name="QWidget"]
   /struct
    /method[@name="QWidget::resize"]
     /param[2][
           not(following-sibling::param) or
           following-sibling::param[1]/default]
      /..
    });
}
$e = time;
print $e - $s, "\n";

I ran that script several times, and they all fell between 1.55 and
1.57 seconds total for the 1000 iterations.

I tried several different functions in various classes with various
parameter counts, the the speed doesn't change.

Also, removing everything after /method[@name="QWidget::resize"] only
reduces the total runtime to 1.49-1.52 seconds, meaning I can probably
add all sorts of complicated XPath heuristic voodoo (such as checking
for param[1]/pointer/type[@name="QRect"]) without slowing down the
lookup significantly.

So, that leaves me able to run >500 new XPath queries per second from
Perl. Probably a few more if you squeeze it into C++, but I think
that's  a premature optimization. And once I get a result, I can cache
it in a hash using the XPath query as the key, and the nodelist as the
value.

Ashley Winters


		
____________________________________________________ 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com



More information about the Kde-bindings mailing list