Benchmark multiple functions, with three different length int values.
()
| 90 | |
| 91 | |
| 92 | def 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 | |
| 109 | if __name__ == "__main__": |
no test coverage detected