Skip to content

Commit bb42746

Browse files
committed
Created decorators_tarik_bozgan.py
1 parent 06cd05c commit bb42746

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Week04/decorators_tarik_bozgan.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def custom_power(x, e=1):
2+
return x ** e
3+
4+
def custom_equation(x, y, a=1, b=1, *, c=1):
5+
return (x ** a + y ** b) / c
6+
7+
_calls = {}
8+
9+
def fn_w_counter():
10+
caller = __import__('inspect').currentframe().f_back.f_code.co_name
11+
_calls[caller] = _calls.get(caller, 0) + 1
12+
return (_calls[caller], dict(_calls))
13+
14+
def performance(f):
15+
def w(*a, **k):
16+
import time, tracemalloc
17+
tracemalloc.start()
18+
t = time.time()
19+
r = f(*a, **k)
20+
w.total_time += time.time() - t
21+
w.total_mem += tracemalloc.get_traced_memory()[0]
22+
tracemalloc.stop()
23+
w.counter += 1
24+
return r
25+
w.counter = w.total_time = w.total_mem = 0
26+
return w

0 commit comments

Comments
 (0)