Skip to content

Commit

Permalink
Merge pull request #185 from batuhan023/patch-7
Browse files Browse the repository at this point in the history
Create decorators_batuhan_yavuz.py
  • Loading branch information
canbula committed Oct 24, 2023
2 parents 5c0a3cf + e045640 commit 9656e30
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Week03/decorators_batuhan_yavuz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import time,tracemalloc
def performance(func):
def wrapper(*args,**kwargs):
if not hasattr(performance,'counter'):
performance.counter = 0
performance.total_time = 0
performance.total_mem = 0

performance.counter +=1
start = time.perf_counter()
tracemalloc.start()
result = func(*args,**kwargs)
end = time.perf_counter()
execution_time = end - start
performance.total_time += execution_time
performance.total_mem += tracemalloc.get_traced_memory()[1]
return result

return wrapper

0 comments on commit 9656e30

Please sign in to comment.