diff --git a/Week04/decorators_onur_konuk.py b/Week04/decorators_onur_konuk.py new file mode 100644 index 00000000..cccb0272 --- /dev/null +++ b/Week04/decorators_onur_konuk.py @@ -0,0 +1,23 @@ +import time +import tracemalloc + +def performance(func): + performance.counter = 0 + performance.total_time = 0 + performance.total_mem = 0 + + def wrapper(*args, **kwargs): + tracemalloc.start() + start_time = time.perf_counter() + result = func(*args, **kwargs) + end_time = time.perf_counter() + current, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + + performance.counter += 1 + performance.total_time += (end_time - start_time) + performance.total_mem += peak + + return result + + return wrapper