1.1 --- a/tests/begat.py Sun Feb 27 18:32:58 2011 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,83 +0,0 @@
1.4 -#!/usr/bin/env python
1.5 -
1.6 -"""
1.7 -The controversial "begat" benchmark. This module must be compiled using
1.8 -libxml2macro.py before use, and must then be invoked directly as a compiled
1.9 -module - ie. as begat.pyc.
1.10 -"""
1.11 -
1.12 -import libxml2macro as n_
1.13 -
1.14 -def test_begat_libxml2macro(n_doc, full_xpath):
1.15 - l = []
1.16 -
1.17 - if full_xpath:
1.18 - for n_node in n_doc.xpath("//v[contains(text(), 'begat')]"):
1.19 - text = n_node.nodeValue
1.20 - l.append(text)
1.21 - else:
1.22 - # NOTE: Code corresponding to this was suggested for cElementTree, but why not
1.23 - # NOTE: take full advantage of XPath if you have most of the code written in C?
1.24 -
1.25 - for n_node in n_doc.xpath("//v"):
1.26 - text = n_node.nodeValue
1.27 - if text.find(u'begat') != -1:
1.28 - l.append(text)
1.29 -
1.30 - return l
1.31 -
1.32 -def test_begat_libxml2dom(doc, full_xpath):
1.33 - l = []
1.34 -
1.35 - if full_xpath:
1.36 - for node in doc.xpath("//v[contains(text(), 'begat')]"):
1.37 - text = node.nodeValue
1.38 - l.append(text)
1.39 - else:
1.40 - # NOTE: Code corresponding to this was suggested for cElementTree, but why not
1.41 - # NOTE: take full advantage of XPath if you have most of the code written in C?
1.42 -
1.43 - for node in doc.xpath("//v"):
1.44 - text = node.nodeValue
1.45 - if text.find(u'begat') != -1:
1.46 - l.append(text)
1.47 -
1.48 - return l
1.49 -
1.50 -if __name__ == "__main__":
1.51 - import time, os
1.52 - import sys
1.53 -
1.54 - ot_locations = [arg for arg in sys.argv if arg.endswith("ot.xml")]
1.55 - full_xpath = "--full" in sys.argv
1.56 - use_libxml2dom = "libxml2dom" in sys.argv
1.57 - use_libxml2macro = "libxml2macro" in sys.argv
1.58 - iterations = [int(arg.split("-")[0]) for arg in sys.argv if arg.endswith("-times")]
1.59 -
1.60 - if len(ot_locations) == 0:
1.61 - print "Please specify the location of the ot.xml file."
1.62 - sys.exit(1)
1.63 -
1.64 - if len(iterations) == 0:
1.65 - iterations = 1
1.66 - else:
1.67 - iterations = iterations[0]
1.68 -
1.69 - raw_input("Start your engines with ps -p %s -fv" % os.getpid())
1.70 - t = time.time()
1.71 -
1.72 - for i in range(0, iterations):
1.73 - if use_libxml2macro:
1.74 - n_doc = parseFile(ot_locations[0])
1.75 - l = test_begat_libxml2macro(n_doc, full_xpath)
1.76 - else: # use_libxml2dom:
1.77 - import libxml2dom
1.78 - doc = libxml2dom.parse(ot_locations[0])
1.79 - l = test_begat_libxml2dom(doc, full_xpath)
1.80 -
1.81 - print "Time taken", time.time() - t
1.82 - raw_input("Stop your engines!")
1.83 -
1.84 - print l
1.85 -
1.86 -# vim: tabstop=4 expandtab shiftwidth=4