Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-142145: Avoid timing measurements in quadratic behavior test#143105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,7 +2,6 @@ | ||
| import copy | ||
| import pickle | ||
| import io | ||
| from test import support | ||
| import unittest | ||
| @@ -178,23 +177,36 @@ def testAppendChild(self): | ||
| def testAppendChildNoQuadraticComplexity(self): | ||
| impl = getDOMImplementation() | ||
| def work(n): | ||
| doc = impl.createDocument(None, "some_tag", None) | ||
| element = doc.documentElement | ||
| total_calls = 0 | ||
| # Count attribute accesses as a proxy for work done | ||
| def getattribute_counter(self, attr): | ||
| nonlocal total_calls | ||
| total_calls += 1 | ||
| return object.__getattribute__(self, attr) | ||
| with support.swap_attr(Element, "__getattribute__", getattribute_counter): | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. doing this is... gross, but likely works. your the other thought i was having as i did the simple "raise the timeout to 4s" to unblock the earlier ones was that we don't need absolute times at all. measuring relative time taken as we increase the amount of work to ensure that it scales - similar to this scaling measurement of attribute accesses - would be sufficient and should produce similar results on super slow builds or heavily loaded systems. it would still be time based (so maybe use we have a smattering of other timing based cpu performancy tests in the repo. i don't think we've codified a reusable best practice. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
It'd be great to have some sort of standard best practice for this. If Some other things I was thinking about:
| ||
| for _ in range(n): | ||
| child = doc.createElement("child") | ||
| element.appendChild(child) | ||
| element = child | ||
| return total_calls | ||
| # Doubling N should not ~quadruple the work. | ||
| w1 = work(1024) | ||
| w2 = work(2048) | ||
| w3 = work(4096) | ||
| self.assertGreater(w1, 0) | ||
| r1 = w2 / w1 | ||
| r2 = w3 / w2 | ||
| self.assertLess( | ||
| max(r1, r2), 3.2, | ||
| msg=f"Possible quadratic behavior: work={w1,w2,w3} ratios={r1,r2}" | ||
| ) | ||
| def testSetAttributeNodeWithoutOwnerDocument(self): | ||
| # regression test for gh-142754 | ||
Uh oh!
There was an error while loading.Please reload this page.