MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / benchmark

Function benchmark

matrix/pascal_triangle.py:166–182  ·  view source on GitHub ↗

Benchmark multiple functions, with three different length int values.

()

Source from the content-addressed store, hash-verified

164
165
166def benchmark() -> None:
167 """
168 Benchmark multiple functions, with three different length int values.
169 """
170 from collections.abc import Callable
171 from timeit import timeit
172
173 def benchmark_a_function(func: Callable, value: int) -> None:
174 call = f"{func.__name__}({value})"
175 timing = timeit(f"__main__.{call}", setup="import __main__")
176 # print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
177 print(f"{call:38} -- {timing:.4f} seconds")
178
179 for value in range(15): # (1, 7, 14):
180 for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
181 benchmark_a_function(func, value)
182 print()
183
184
185if __name__ == "__main__":

Callers 1

pascal_triangle.pyFile · 0.70

Calls 1

benchmark_a_functionFunction · 0.70

Tested by

no test coverage detected