Times the execution of a function with parameters
(func, *args, **kwargs)
| 24 | |
| 25 | |
| 26 | def time_func(func, *args, **kwargs): |
| 27 | """ |
| 28 | Times the execution of a function with parameters |
| 29 | """ |
| 30 | start = time() |
| 31 | output = func(*args, **kwargs) |
| 32 | end = time() |
| 33 | if int(end - start) > 0: |
| 34 | print(f"{func.__name__} runtime: {(end - start):0.4f} s") |
| 35 | else: |
| 36 | print(f"{func.__name__} runtime: {(end - start) * 1000:0.4f} ms") |
| 37 | return output |
| 38 | |
| 39 | |
| 40 | def fib_iterative_yield(n: int) -> Iterator[int]: |