Skip to content
Open
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
29 changes: 29 additions & 0 deletions Week04/decorators_fevzi_bagriacik.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import time
import tracemalloc
from functools import wraps


class performance:
counter = 0
total_time = 0.0
total_mem = 0

def __init__(self, func):
self.func = func
wraps(func)(self)

def __call__(self, *args, **kwargs):
tracemalloc.start()
start_time = time.perf_counter()

result = self.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