# HG changeset patch # User paulb # Date 1105842590 0 # Node ID b79d1ca72dc31428ccaa3c583bda14c87d7c88d3 # Parent 5389e482904856867c0630438f261a02020287bd [project @ 2005-01-16 02:29:50 by paulb] Added a performance measurement test program. diff -r 5389e4829048 -r b79d1ca72dc3 tests/performance.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/performance.py Sun Jan 16 02:29:50 2005 +0000 @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +import macrotest +import xml.dom.minidom +import libxml2dom +import xml.dom +import time +import sys + +def find_root(d): + root = None + + for n in d.childNodes: + if n.nodeType == xml.dom.Node.ELEMENT_NODE: + root = n + break + + return root + +def test_import(d): + d2 = xml.dom.minidom.getDOMImplementation().createDocument("nsD", "newdoc", None) + imported = d2.importNode(find_root(d), 1) + d2.replaceChild(imported, find_root(d2)) + return d, d2 + +def test_import2(d): + d2 = libxml2dom.createDocument("nsD", "newdoc", None) + imported = d2.importNode(find_root(d), 1) + d2.replaceChild(imported, find_root(d2)) + return d, d2 + +x2_d = macrotest.parseFile(sys.argv[1]) + +t = time.time() +x2_d1, x2_d2 = macrotest.test_import(x2_d) +print "Time", time.time() - t, "seconds" + +d = xml.dom.minidom.parse(sys.argv[1]) + +t = time.time() +d1, d2 = test_import(d) +print "Time", time.time() - t, "seconds" + +d = libxml2dom.parse(sys.argv[1]) + +t = time.time() +d1, d2 = test_import2(d) +print "Time", time.time() - t, "seconds" + +# vim: tabstop=4 expandtab shiftwidth=4