Skip to content

Commit

Permalink
Merge pull request #274 from AtaAlaca/patch-4
Browse files Browse the repository at this point in the history
Create decorators_ata_ceyhun_alaca.py
  • Loading branch information
canbula committed Nov 7, 2023
2 parents ad0c519 + fc24617 commit 8630050
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Week03/decorators_ata_ceyhun_alaca.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import time
import tracemalloc


def performance(func):
"""
:param func:
:return: A decorated function that measures performance.
"""
if not hasattr(performance, "counter"):
performance.counter = 0
performance.total_time = 0
performance.total_mem = 0

def decorated_function(*args, **kwargs):
start_time = time.perf_counter()
performance.counter += 1

tracemalloc.start()
result = func(*args, **kwargs)
end_time = time.perf_counter()

performance.total_mem += tracemalloc.get_traced_memory()[1]
tracemalloc.stop()
performance.total_time += (end_time - start_time)
return result

return decorated_function

0 comments on commit 8630050

Please sign in to comment.