Skip to content

Commit

Permalink
Merge pull request #202 from bestetekceli/patch-4
Browse files Browse the repository at this point in the history
Create decorators_havva_beste_tekceli.py
  • Loading branch information
canbula committed Oct 22, 2023
2 parents ca5ced7 + 5e16845 commit 9d25741
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 9d25741

Please sign in to comment.