mirror of https://github.com/bitcoin/bitcoin.git
Merge bitcoin/bitcoin#33313: test/refactor: use test deque to avoid quadratic iteration
75e6984ec8
test/refactor: use test deque to avoid quadratic iteration (Lőrinc) Pull request description: Extracted from https://github.com/bitcoin/bitcoin/pull/33141#discussion_r2323012972. ----- In Python, [list `pop(0)` is linear](https://docs.python.org/3/tutorial/datastructures.html#using-lists-as-queues), so consuming all items in the test results in quadratic iteration. Switching to `collections.deque` with `popleft()` expresses FIFO intent and avoids the O(n^2) path. Behavior is unchanged - for a few hundred items the perf impact is likely negligible. ACKs for top commit: maflcko: lgtm ACK75e6984ec8
theStack: re-ACK75e6984ec8
enirox001: reACK75e6984
w0xlt: reACK75e6984ec8
Tree-SHA512: 290f6aeeb33d8b12b7acbbfede7ce0bef1c831a7ab9efc9c3a08c049986572e289cdece0844db908cf198395f574575ce4073c268033bf6dbaadc3828c96c1d8
This commit is contained in:
commit
200150beba
|
@ -454,8 +454,8 @@ def main():
|
||||||
print("Re-compile with the -DBUILD_DAEMON=ON build option")
|
print("Re-compile with the -DBUILD_DAEMON=ON build option")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Build list of tests
|
# Build tests
|
||||||
test_list = []
|
test_list = deque()
|
||||||
if tests:
|
if tests:
|
||||||
# Individual tests have been specified. Run specified tests that exist
|
# Individual tests have been specified. Run specified tests that exist
|
||||||
# in the ALL_SCRIPTS list. Accept names with or without a .py extension.
|
# in the ALL_SCRIPTS list. Accept names with or without a .py extension.
|
||||||
|
@ -474,7 +474,7 @@ def main():
|
||||||
script = script + ".py" if ".py" not in script else script
|
script = script + ".py" if ".py" not in script else script
|
||||||
matching_scripts = [s for s in ALL_SCRIPTS if s.startswith(script)]
|
matching_scripts = [s for s in ALL_SCRIPTS if s.startswith(script)]
|
||||||
if matching_scripts:
|
if matching_scripts:
|
||||||
test_list.extend(matching_scripts)
|
test_list += matching_scripts
|
||||||
else:
|
else:
|
||||||
print("{}WARNING!{} Test '{}' not found in full test list.".format(BOLD[1], BOLD[0], test))
|
print("{}WARNING!{} Test '{}' not found in full test list.".format(BOLD[1], BOLD[0], test))
|
||||||
elif args.extended:
|
elif args.extended:
|
||||||
|
@ -509,7 +509,7 @@ def main():
|
||||||
remove_tests([test for test in test_list if test.split('.py')[0] == exclude_test.split('.py')[0]])
|
remove_tests([test for test in test_list if test.split('.py')[0] == exclude_test.split('.py')[0]])
|
||||||
|
|
||||||
if args.filter:
|
if args.filter:
|
||||||
test_list = list(filter(re.compile(args.filter).search, test_list))
|
test_list = deque(filter(re.compile(args.filter).search, test_list))
|
||||||
|
|
||||||
if not test_list:
|
if not test_list:
|
||||||
print("No valid test scripts specified. Check that your test is in one "
|
print("No valid test scripts specified. Check that your test is in one "
|
||||||
|
@ -726,7 +726,7 @@ class TestHandler:
|
||||||
def get_next(self):
|
def get_next(self):
|
||||||
while len(self.jobs) < self.num_jobs and self.test_list:
|
while len(self.jobs) < self.num_jobs and self.test_list:
|
||||||
# Add tests
|
# Add tests
|
||||||
test = self.test_list.pop(0)
|
test = self.test_list.popleft()
|
||||||
portseed = len(self.test_list)
|
portseed = len(self.test_list)
|
||||||
portseed_arg = ["--portseed={}".format(portseed)]
|
portseed_arg = ["--portseed={}".format(portseed)]
|
||||||
log_stdout = tempfile.SpooledTemporaryFile(max_size=2**16)
|
log_stdout = tempfile.SpooledTemporaryFile(max_size=2**16)
|
||||||
|
@ -754,8 +754,7 @@ class TestHandler:
|
||||||
]
|
]
|
||||||
fut = self.executor.submit(proc_wait, task)
|
fut = self.executor.submit(proc_wait, task)
|
||||||
self.jobs[fut] = test
|
self.jobs[fut] = test
|
||||||
if not self.jobs:
|
assert self.jobs # Must not be empty here
|
||||||
raise IndexError('pop from empty list')
|
|
||||||
|
|
||||||
# Print remaining running jobs when all jobs have been started.
|
# Print remaining running jobs when all jobs have been started.
|
||||||
if not self.test_list:
|
if not self.test_list:
|
||||||
|
|
Loading…
Reference in New Issue