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

Function benchmark

maths/number_of_digits.py:92–106  ·  view source on GitHub ↗

Benchmark multiple functions, with three different length int values.

()

Source from the content-addressed store, hash-verified

90
91
92def benchmark() -> None:
93 """
94 Benchmark multiple functions, with three different length int values.
95 """
96 from collections.abc import Callable
97
98 def benchmark_a_function(func: Callable, value: int) -> None:
99 call = f"{func.__name__}({value})"
100 timing = timeit(f"__main__.{call}", setup="import __main__")
101 print(f"{call}: {func(value)} -- {timing} seconds")
102
103 for value in (262144, 1125899906842624, 1267650600228229401496703205376):
104 for func in (num_digits, num_digits_fast, num_digits_faster):
105 benchmark_a_function(func, value)
106 print()
107
108
109if __name__ == "__main__":

Callers 1

Calls 1

benchmark_a_functionFunction · 0.70

Tested by

no test coverage detected