From 870b6f8473f4eb18492959044d143ecb86e6db0b Mon Sep 17 00:00:00 2001 From: scoder Date: Fri, 27 Oct 2006 08:52:09 +0200 Subject: [svn r2005] fixes in bench_objectify.py, some more benchmarks --HG-- branch : trunk --- benchmark/bench_objectify.py | 50 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'benchmark') diff --git a/benchmark/bench_objectify.py b/benchmark/bench_objectify.py index 672f86ad..b3df645d 100644 --- a/benchmark/bench_objectify.py +++ b/benchmark/bench_objectify.py @@ -2,12 +2,6 @@ import sys, copy from itertools import * from StringIO import StringIO -from lxml import etree, objectify - -parser = etree.XMLParser(remove_blank_text=True) -lookup = etree.ElementNamespaceClassLookup(objectify.ObjectifyElementClassLookup()) -parser.setElementClassLookup(lookup) - import benchbase from benchbase import with_attributes, with_text, onlylib, serialized @@ -17,13 +11,24 @@ from benchbase import with_attributes, with_text, onlylib, serialized class BenchMark(benchbase.BenchMarkBase): def __init__(self, lib): - benchbase.BenchMarkBase.__init__(self, lib, parser) + from lxml import etree, objectify + self.objectify = objectify + parser = etree.XMLParser(remove_blank_text=True) + lookup = objectify.ObjectifyElementClassLookup() + parser.setElementClassLookup(lookup) + super(BenchMark, self).__init__(etree, parser) - def bench_attributes(self, root): + def bench_attribute(self, root): "1 2 4" for i in repeat(None, 3000): root.zzzzz + def bench_attribute_cached(self, root): + "1 2 4" + cache = root.zzzzz + for i in repeat(None, 3000): + root.zzzzz + def bench_attributes_deep(self, root): "1 2 4" for i in repeat(None, 3000): @@ -38,13 +43,13 @@ class BenchMark(benchbase.BenchMarkBase): def bench_objectpath(self, root): "1 2 4" - path = objectify.ObjectPath(".zzzzz") + path = self.objectify.ObjectPath(".zzzzz") for i in repeat(None, 3000): path(root) def bench_objectpath_deep(self, root): "1 2 4" - path = objectify.ObjectPath(".zzzzz.{cdefg}z00000") + path = self.objectify.ObjectPath(".zzzzz.{cdefg}z00000") for i in repeat(None, 3000): path(root) @@ -52,9 +57,32 @@ class BenchMark(benchbase.BenchMarkBase): "1 2 4" cache1 = root.zzzzz cache2 = cache1['{cdefg}z00000'] - path = objectify.ObjectPath(".zzzzz.{cdefg}z00000") + path = self.objectify.ObjectPath(".zzzzz.{cdefg}z00000") for i in repeat(None, 3000): path(root) + @with_text(text=True, utext=True, no_text=True) + def bench_annotate(self, root): + self.objectify.annotate(root) + + def bench_descendantpaths(self, root): + root.descendantpaths() + + @with_text(text=True) + def bench_type_inference(self, root): + "1 2 4" + el = root.aaaaa + for i in repeat(None, 1000): + el.getchildren() + + @with_text(text=True) + def bench_type_inference_annotated(self, root): + "1 2 4" + el = root.aaaaa + self.objectify.annotate(el) + for i in repeat(None, 1000): + el.getchildren() + + if __name__ == '__main__': benchbase.main(BenchMark) -- cgit v1.2.1