Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Week04/decorators_rukiye_ilhan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import tracemalloc
import time


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

def perform(*args,**kwargs):
tracemalloc.start() # start to follow memory
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
used_memory = tracemalloc.get_traced_memory()[1] # [0] gives current memory consumption but [1] gives total(max) memory consumption during thr last fallowing time
tracemalloc.stop() # we started memeory following process only to find how much memory uses by thr called function not the entire program ,so we stop memory following when the jop of function is finished
performance.counter += 1
performance.total_time += end_time - start_time
performance.total_mem += used_memory
return result
return perform
Loading