Skip to content

Commit e923836

Browse files
authored
Add files via upload
1 parent 208f3d9 commit e923836

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

Week04/decorators_halilturker_eren.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import time
2+
import tracemalloc
3+
4+
5+
def performance(func):
6+
setattr(performance, 'counter', 0)
7+
setattr(performance, 'total_time', 0.0)
8+
setattr(performance, 'total_mem', 0.0)
9+
10+
def wrapper(*args, **kwargs):
11+
tracemalloc.start()
12+
start_time = time.time()
13+
result = func(*args, **kwargs)
14+
end_time = time.time()
15+
current, peak = tracemalloc.get_traced_memory()
16+
tracemalloc.stop()
17+
setattr(performance, 'counter', getattr(performance, 'counter') + 1)
18+
setattr(performance, 'total_time', getattr(performance, 'total_time') + end_time - start_time)
19+
setattr(performance, 'total_mem', getattr(performance, 'total_mem') + peak)
20+
return result
21+
22+
return wrapper

Week04/functions_halilturker_eren.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
custom_power = lambda x=0, /, e=1: x ** e
2+
3+
4+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
5+
6+
return (x ** a + y ** b) / c
7+
8+
9+
def fn_w_counter() -> (int, dict[str, int]):
10+
11+
if not hasattr(fn_w_counter, "count"):
12+
setattr(fn_w_counter, "count", 0)
13+
setattr(fn_w_counter, "caller_dict", {})
14+
15+
fn_w_counter.count += 1
16+
caller = __name__
17+
18+
if caller not in fn_w_counter.caller_dict:
19+
fn_w_counter.caller_dict[caller] = 0
20+
21+
fn_w_counter.caller_dict[caller] += 1
22+
23+
return (int(fn_w_counter.count), dict(fn_w_counter.caller_dict))

0 commit comments

Comments
 (0)