Skip to content

Commit

Permalink
Merge pull request #206 from cengizhancam/patch-1
Browse files Browse the repository at this point in the history
Create decorators_cengizhan_cam.py
  • Loading branch information
canbula committed Oct 23, 2023
2 parents 9d90957 + 35d94a2 commit 81a449b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Week03/decorators_cengizhan_cam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import time
import tracemalloc

def performance(func):
if not hasattr(performance, "counter"):
performance.counter = 0
performance.total_time = 0
performance.total_mem = 0

def wrapped_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 wrapped_function

0 comments on commit 81a449b

Please sign in to comment.