Skip to content

Commit 8cd5cdc

Browse files
committed
refactor: Combine functions into iteration
1 parent f0a785c commit 8cd5cdc

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

matrix/count_negative_numbers_in_sorted_matrix.py

+7-28
Original file line numberDiff line numberDiff line change
@@ -147,34 +147,13 @@ def benchmark() -> None:
147147
"from __main__ import count_negatives_binary_search,count_negatives_brute_force"
148148
",count_negatives_brute_force_with_break,generate_large_matrix"
149149
)
150-
151-
print(
152-
"count_negatives_binary_search()",
153-
timeit(
154-
"count_negatives_binary_search(generate_large_matrix())",
155-
setup=setup,
156-
number=5000,
157-
),
158-
"seconds",
159-
)
160-
print(
161-
"count_negatives_brute_force_with_break()",
162-
timeit(
163-
"count_negatives_brute_force_with_break(generate_large_matrix())",
164-
setup=setup,
165-
number=5000,
166-
),
167-
"seconds",
168-
)
169-
print(
170-
"count_negatives_brute_force()",
171-
timeit(
172-
"count_negatives_brute_force(generate_large_matrix())",
173-
setup=setup,
174-
number=5000,
175-
),
176-
"seconds",
177-
)
150+
for func in (
151+
"count_negatives_binary_search",
152+
"count_negatives_brute_force_with_break",
153+
"count_negatives_brute_force",
154+
):
155+
time = timeit(f"{func}(generate_large_matrix())", setup=setup, number=5000)
156+
print(f"{func}() took {time} seconds")
178157

179158

180159
if __name__ == "__main__":

0 commit comments

Comments
 (0)