Skip to content

Commit e99952c

Browse files
authored
Merge pull request #1055 from sartikb/patch-5
Create decorators_burak_sartik.py
2 parents 2060eb2 + 52a068b commit e99952c

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Week04/decorators_burak_sartik.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
import tracemalloc
3+
4+
def performance(func):
5+
if not hasattr(performance, 'counter'):
6+
performance.counter = 0
7+
performance.total_time = 0.0
8+
performance.total_mem = 0.0
9+
def wrapper(*args, **kwargs):
10+
tracemalloc.start()
11+
start_time = time.perf_counter()
12+
13+
result = func(*args, **kwargs)
14+
15+
end_time = time.perf_counter()
16+
current_mem, peak_mem = tracemalloc.get_traced_memory()
17+
tracemalloc.stop()
18+
19+
performance.counter += 1
20+
performance.total_time += (end_time - start_time)
21+
performance.total_mem += peak_mem
22+
23+
return result
24+
wrapper.__name__ = func.__name__
25+
wrapper.__doc__ = func.__doc__
26+
27+
return wrapper

0 commit comments

Comments
 (0)