1 #!/usr/bin/env python 2 3 """ 4 The controversial "begat" benchmark. This module must be compiled using 5 libxml2macro.py before use, and must then be invoked directly as a compiled 6 module - ie. as begat.pyc. 7 """ 8 9 import libxml2macro as n_ 10 import time, os 11 12 raw_input("Start your engines with ps -p %s -fv" % os.getpid()) 13 t = time.time() 14 15 l = [] 16 n_doc = parseFile("ot.xml") 17 for n_node in n_doc.xpath("//v[contains(text(), 'begat')]"): 18 text = n_node.nodeValue 19 l.append(text) 20 21 # NOTE: Code corresponding to this was suggested for cElementTree, but why not 22 # NOTE: take full advantage of XPath if you have most of the code written in C? 23 # 24 # for n_node in n_doc.xpath("//v"): 25 # text = n_node.nodeValue 26 # if text.find(u'begat') != -1: 27 # print text 28 29 print "Time taken", time.time() - t 30 raw_input("Stop your engines!") 31 32 print l 33 34 # vim: tabstop=4 expandtab shiftwidth=4