| 1 |
from itertools import * |
| 2 |
|
| 3 |
import benchbase |
| 4 |
from benchbase import (with_text, children, nochange) |
| 5 |
|
| 6 |
############################################################ |
| 7 |
# Benchmarks |
| 8 |
############################################################ |
| 9 |
|
| 10 |
class BenchMark(benchbase.TreeBenchMark): |
| 11 |
repeat100 = range(100) |
| 12 |
repeat1000 = range(1000) |
| 13 |
repeat3000 = range(3000) |
| 14 |
|
| 15 |
def __init__(self, lib): |
| 16 |
from lxml import etree, objectify |
| 17 |
self.objectify = objectify |
| 18 |
parser = etree.XMLParser(remove_blank_text=True) |
| 19 |
lookup = objectify.ObjectifyElementClassLookup() |
| 20 |
parser.set_element_class_lookup(lookup) |
| 21 |
super(BenchMark, self).__init__(etree, parser) |
| 22 |
|
| 23 |
@nochange |
| 24 |
def bench_attribute(self, root): |
| 25 |
"1 2 4" |
| 26 |
for i in self.repeat3000: |
| 27 |
root.zzzzz |
| 28 |
|
| 29 |
def bench_attribute_assign_int(self, root): |
| 30 |
"1 2 4" |
| 31 |
for i in self.repeat3000: |
| 32 |
root.XYZ = 5 |
| 33 |
|
| 34 |
def bench_attribute_assign_string(self, root): |
| 35 |
"1 2 4" |
| 36 |
for i in self.repeat3000: |
| 37 |
root.XYZ = "5" |
| 38 |
|
| 39 |
@nochange |
| 40 |
def bench_attribute_cached(self, root): |
| 41 |
"1 2 4" |
| 42 |
cache = root.zzzzz |
| 43 |
for i in self.repeat3000: |
| 44 |
root.zzzzz |
| 45 |
|
| 46 |
@nochange |
| 47 |
def bench_attributes_deep(self, root): |
| 48 |
"1 2 4" |
| 49 |
for i in self.repeat3000: |
| 50 |
root.zzzzz['{cdefg}a00001'] |
| 51 |
|
| 52 |
@nochange |
| 53 |
def bench_attributes_deep_cached(self, root): |
| 54 |
"1 2 4" |
| 55 |
cache1 = root.zzzzz |
| 56 |
cache2 = cache1['{cdefg}a00001'] |
| 57 |
for i in self.repeat3000: |
| 58 |
root.zzzzz['{cdefg}a00001'] |
| 59 |
|
| 60 |
@nochange |
| 61 |
def bench_objectpath(self, root): |
| 62 |
"1 2 4" |
| 63 |
path = self.objectify.ObjectPath(".zzzzz") |
| 64 |
for i in self.repeat3000: |
| 65 |
path(root) |
| 66 |
|
| 67 |
@nochange |
| 68 |
def bench_objectpath_deep(self, root): |
| 69 |
"1 2 4" |
| 70 |
path = self.objectify.ObjectPath(".zzzzz.{cdefg}a00001") |
| 71 |
for i in self.repeat3000: |
| 72 |
path(root) |
| 73 |
|
| 74 |
@nochange |
| 75 |
def bench_objectpath_deep_cached(self, root): |
| 76 |
"1 2 4" |
| 77 |
cache1 = root.zzzzz |
| 78 |
cache2 = cache1['{cdefg}a00001'] |
| 79 |
path = self.objectify.ObjectPath(".zzzzz.{cdefg}a00001") |
| 80 |
for i in self.repeat3000: |
| 81 |
path(root) |
| 82 |
|
| 83 |
@with_text(text=True, utext=True, no_text=True) |
| 84 |
def bench_annotate(self, root): |
| 85 |
self.objectify.annotate(root) |
| 86 |
|
| 87 |
@nochange |
| 88 |
def bench_descendantpaths(self, root): |
| 89 |
root.descendantpaths() |
| 90 |
|
| 91 |
@nochange |
| 92 |
@with_text(text=True) |
| 93 |
def bench_type_inference(self, root): |
| 94 |
"1 2 4" |
| 95 |
el = root.aaaaa |
| 96 |
for i in self.repeat1000: |
| 97 |
el.getchildren() |
| 98 |
|
| 99 |
@nochange |
| 100 |
@with_text(text=True) |
| 101 |
def bench_type_inference_annotated(self, root): |
| 102 |
"1 2 4" |
| 103 |
el = root.aaaaa |
| 104 |
self.objectify.annotate(el) |
| 105 |
for i in self.repeat1000: |
| 106 |
el.getchildren() |
| 107 |
|
| 108 |
@nochange |
| 109 |
@children |
| 110 |
def bench_elementmaker(self, children): |
| 111 |
E = self.objectify.E |
| 112 |
for child in children: |
| 113 |
root = E.this( |
| 114 |
"test", |
| 115 |
E.will( |
| 116 |
E.do("nothing"), |
| 117 |
E.special, |
| 118 |
) |
| 119 |
) |
| 120 |
|
| 121 |
if __name__ == '__main__': |
| 122 |
benchbase.main(BenchMark) |