MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / benchmark_a_function

Function benchmark_a_function

maths/sum_of_digits.py:59–62  ·  view source on GitHub ↗
(func: Callable, value: int)

Source from the content-addressed store, hash-verified

57 from timeit import timeit
58
59 def benchmark_a_function(func: Callable, value: int) -> None:
60 call = f"{func.__name__}({value})"
61 timing = timeit(f"__main__.{call}", setup="import __main__")
62 print(f"{call:56} = {func(value)} -- {timing:.4f} seconds")
63
64 for value in (262144, 1125899906842624, 1267650600228229401496703205376):
65 for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):

Callers 1

benchmarkFunction · 0.70

Calls 1

funcFunction · 0.85

Tested by

no test coverage detected