Created
December 24, 2018 12:58
-
-
Save RuRo/5278362923870db2ab2c387d02b36512 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import functools | |
timers = {} | |
def timed(func): | |
global timers | |
timers[func] = {"T":0, "N":0} | |
@functools.wraps(func) | |
def wrapped(*args, **kwargs): | |
T = time.perf_counter() | |
res = func(*args, **kwargs) | |
T = time.perf_counter() - T | |
timers[func]["T"] += T | |
timers[func]["N"] += 1 | |
return res | |
return wrapped | |
@timed | |
def my_functions(some, arguments, also, kwarguments=None): | |
pass | |
if __name__ == '__main__': | |
my_functions(1, 2, 3) | |
print("\n".join("Time spent in {:>24}: {} sec over {} iterations".format(func.__name__, T['T'], T['N']) | |
for func, T in timers.items())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment