MCPcopy Index your code
hub / github.com/python/cpython / work

Method work

Lib/test/test_minidom.py:180–196  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

178 impl = getDOMImplementation()
179
180 def work(n):
181 doc = impl.createDocument(None, "some_tag", None)
182 element = doc.documentElement
183 total_calls = 0
184
185 # Count attribute accesses as a proxy for work done
186 def getattribute_counter(self, attr):
187 nonlocal total_calls
188 total_calls += 1
189 return object.__getattribute__(self, attr)
190
191 with support.swap_attr(Element, "__getattribute__", getattribute_counter):
192 for _ in range(n):
193 child = doc.createElement("child")
194 element.appendChild(child)
195 element = child
196 return total_calls
197
198 # Doubling N should not ~quadruple the work.
199 w1 = work(1024)

Callers

nothing calls this directly

Calls 3

createDocumentMethod · 0.80
createElementMethod · 0.80
appendChildMethod · 0.45

Tested by

no test coverage detected