Skip to content

Commit

Permalink
Merge pull request #263 from yavuzserdogan/patch-4
Browse files Browse the repository at this point in the history
Create decorators_yavuz_selim_erdogan.py
  • Loading branch information
canbula committed Nov 3, 2023
2 parents e1d4ac1 + 76be09e commit 2097761
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Week03/decorators_yavuz_selim_erdogan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import time
import tracemalloc


def performance(function):
def wrapper(*args, **kwargs):
if not hasattr(performance, "counter"):
performance.counter = 0
if not hasattr(performance, "total_time"):
performance.total_time = 0
if not hasattr(performance, "total_mem"):
performance.total_mem = 0

tracemalloc.start()
start_time = time.perf_counter()
start_mem = tracemalloc.get_traced_memory()[1]
function(*args, **kwargs)
end_time = time.perf_counter()
end_mem = tracemalloc.get_traced_memory()[1]

performance.counter += 1
performance.total_time += end_time - start_time
performance.total_mem += end_mem - start_mem

return function

return wrapper

0 comments on commit 2097761

Please sign in to comment.