1.1 --- a/tests/performance.py Mon Jan 24 16:37:46 2005 +0000
1.2 +++ b/tests/performance.py Mon Jan 24 16:38:55 2005 +0000
1.3 @@ -1,59 +1,83 @@
1.4 #!/usr/bin/env python
1.5
1.6 -import macrotest
1.7 -import xml.dom.minidom
1.8 -import libxml2dom
1.9 +"""
1.10 +A performance test using libxml2dom.macrolib, libxml2dom and minidom.
1.11 +This module must be compiled using libxml2macro.py and run only as a compiled
1.12 +module - ie. as performance.pyc.
1.13 +"""
1.14 +
1.15 import xml.dom
1.16 -import time
1.17 -import sys
1.18
1.19 def find_root(d):
1.20 root = None
1.21 -
1.22 for n in d.childNodes:
1.23 if n.nodeType == xml.dom.Node.ELEMENT_NODE:
1.24 root = n
1.25 break
1.26 -
1.27 return root
1.28
1.29 -def test_import(d):
1.30 +import libxml2macro as x2_
1.31 +
1.32 +def find_root_libxml2macro(x2_d):
1.33 + x2_root = None
1.34 + for x2_n in x2_d.childNodes:
1.35 + if x2_n.nodeType == xml.dom.Node.ELEMENT_NODE:
1.36 + x2_root = x2_n
1.37 + break
1.38 + return x2_root
1.39 +
1.40 +def test_import_libxml2macro(x2_d):
1.41 + x2_d2 = createDocument("nsD", "newdoc", None)
1.42 + x2_imported = x2_d.importNode(find_root_libxml2macro(x2_d), 1)
1.43 + x2_d2.replaceChild(x2_imported, find_root_libxml2macro(x2_d2))
1.44 + return x2_d, x2_d2
1.45 +
1.46 +def test_import_minidom(d):
1.47 d2 = xml.dom.minidom.getDOMImplementation().createDocument("nsD", "newdoc", None)
1.48 imported = d2.importNode(find_root(d), 1)
1.49 d2.replaceChild(imported, find_root(d2))
1.50 return d, d2
1.51
1.52 -def test_import2(d):
1.53 +def test_import_libxml2dom(d):
1.54 d2 = libxml2dom.createDocument("nsD", "newdoc", None)
1.55 imported = d2.importNode(find_root(d), 1)
1.56 d2.replaceChild(imported, find_root(d2))
1.57 return d, d2
1.58
1.59 if __name__ == "__main__":
1.60 - if sys.argv[2] == "macrotest":
1.61 + import sys
1.62 + import time
1.63
1.64 - x2_d = macrotest.parseFile(sys.argv[1])
1.65 + if len(sys.argv) < 3:
1.66 + print "Please specify a filename (of a fairly large XML document) and the testing mode."
1.67 + print "There are quite a few large files in the libxml2 distribution."
1.68 + print "For the testing mode, choose one of libxml2macro, minidom, libxml2dom."
1.69 + sys.exit(1)
1.70 +
1.71 + if sys.argv[2] == "libxml2macro":
1.72 +
1.73 + x2_d = parseFile(sys.argv[1])
1.74
1.75 t = time.time()
1.76 - x2_d1, x2_d2 = macrotest.test_import(x2_d)
1.77 - macrotest.toFile(x2_d2, "/tmp/xxx_macrotest.xml")
1.78 + x2_d1, x2_d2 = test_import_libxml2macro(x2_d)
1.79 + toFile(x2_d2, "/tmp/xxx_libxml2macro.xml")
1.80 print "Time", time.time() - t, "seconds"
1.81
1.82 elif sys.argv[2] == "minidom":
1.83 -
1.84 + import xml.dom.minidom
1.85 d = xml.dom.minidom.parse(sys.argv[1])
1.86
1.87 t = time.time()
1.88 - d1, d2 = test_import(d)
1.89 + d1, d2 = test_import_minidom(d)
1.90 open("/tmp/xxx_minidom.xml", "wb").write(d2.toxml("utf-8"))
1.91 print "Time", time.time() - t, "seconds"
1.92
1.93 elif sys.argv[2] == "libxml2dom":
1.94 -
1.95 + import libxml2dom
1.96 d = libxml2dom.parse(sys.argv[1])
1.97
1.98 t = time.time()
1.99 - d1, d2 = test_import2(d)
1.100 + d1, d2 = test_import_libxml2dom(d)
1.101 libxml2dom.toStream(d2, open("/tmp/xxx_libxml2dom.xml", "wb"))
1.102 print "Time", time.time() - t, "seconds"
1.103