Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Week04/decorators_zahra_ismayilli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import time
import tracemalloc

def performance(func):
def wrapper(*args, **kwargs):
performance.counter += 1

tracemalloc.start()
start_time = time.perf_counter()

try:
result = func(*args, **kwargs)
return result
finally:
end_time = time.perf_counter()
current, peak = tracemalloc.get_traced_memory()

performance.total_time += end_time - start_time
performance.total_mem += peak

tracemalloc.stop()

return wrapper


performance.counter = 0
performance.total_time = 0.0
performance.total_mem = 0
Loading