Skip to content

Commit 2c6bcc4

Browse files
kamalesh-babulaldrakenclimber
authored andcommitted
tests/ftests: speed up is_output_same() line compare loop
is_output_same() used to call expected_out.splitlines() on every iteration and index into the freshly built list. Switching to enumerate(zip(out_lines, exp_lines)) lets us split both strings once and walk the pairs directly. A quick timeit run (1,000,000 iterations with matching output) shows the new loop shaving ~5% off the runtime: old: 0.18783240672200918 new: 0.1784688732586801 While tiny in absolute terms, this removes needless allocations and makes the helper more future-proof. Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
1 parent 9bd62ff commit 2c6bcc4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tests/ftests/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,17 @@ def is_output_same(config, out, expected_out):
9393
result = True
9494
cause = None
9595

96-
for line_num, line in enumerate(out.splitlines()):
97-
if line.strip() != expected_out.splitlines()[line_num].strip():
96+
out_lines = out.splitlines()
97+
exp_lines = expected_out.splitlines()
98+
99+
for line_num, (line, exp_line) in enumerate(zip(out_lines, exp_lines)):
100+
if line.strip() != exp_line.strip():
98101
cause = (
99102
'Expected line:\n\t{}\nbut received line:\n\t{}'
100-
''.format(expected_out.splitlines()[line_num].strip(), line.strip())
103+
''.format(exp_line.strip(), line.strip())
101104
)
102105
result = False
106+
break
103107

104108
return result, cause
105109

0 commit comments

Comments
 (0)