Skip to content

Commit

Permalink
Create decorators_havva_beste_tekceli.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bestetekceli committed Oct 22, 2023
1 parent 42303cb commit 5e16845
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Week03/decorators_havva_beste_tekceli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import time
import tracemalloc

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

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

performance.counter += 1
performance.total_time += end_time - start_time
performance.total_mem += mem_used
return function
return _performance

0 comments on commit 5e16845

Please sign in to comment.