| 80 | |
| 81 | def decorator(f): |
| 82 | def wrapper(*args, **kwargs): |
| 83 | timer_kwargs.update(print_at_exit=False) |
| 84 | with Timer(**timer_kwargs) as t: |
| 85 | for _ in range(run_times): |
| 86 | out = f(*args, **kwargs) |
| 87 | fmt = '[*] Execution time of function "%(function_name)s" for %(run_times)d runs is %(execution_time)s = %(execution_time_each)s * %(run_times)d [*]' |
| 88 | context = {'function_name': f.__name__, 'run_times': run_times, 'execution_time': t, 'execution_time_each': t.fmt(t.elapsed / run_times)[1]} |
| 89 | print(fmt % context) |
| 90 | return out |
| 91 | return wrapper |
| 92 | |
| 93 | return decorator |