Skip to content

Commit 1e3aa32

Browse files
authored
Merge pull request #639 from rukiye-ilhan/patch-11
Create decorators_rukiye_ilhan.py
2 parents 6919f86 + 116ec47 commit 1e3aa32

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Week04/decorators_rukiye_ilhan.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import tracemalloc
2+
import time
3+
4+
5+
def performance(func):
6+
if not hasattr(performance,'counter'):
7+
performance.counter = 0
8+
performance.total_time = 0
9+
performance.total_mem = 0
10+
11+
def perform(*args,**kwargs):
12+
tracemalloc.start() # start to follow memory
13+
start_time = time.time()
14+
result = func(*args, **kwargs)
15+
end_time = time.time()
16+
used_memory = tracemalloc.get_traced_memory()[1] # [0] gives current memory consumption but [1] gives total(max) memory consumption during thr last fallowing time
17+
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
18+
performance.counter += 1
19+
performance.total_time += end_time - start_time
20+
performance.total_mem += used_memory
21+
return result
22+
return perform

0 commit comments

Comments
 (0)