-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc.py
More file actions
30 lines (27 loc) · 779 Bytes
/
proc.py
File metadata and controls
30 lines (27 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import inspect
from time import process_time_ns
async def afibo(n: int = 30):
if n == 0:
return 0
if n == 1:
return 1
return await afibo(n - 1) + await afibo(n - 2)
def fibo(n: int = 30):
if n == 0:
return 0
if n == 1:
return 1
return fibo(n - 1) + fibo(n - 2)
# decorator to measure time
def measure_time(func):
def wrapper(*args, **kwargs):
with open("measure_time.csv", "a", encoding="utf-8") as f:
start = process_time_ns()
result = func(*args, **kwargs)
end = process_time_ns()
f.write(
f'{inspect.getfile(func).split("/")[-1].replace(".py", "")}'
f',{end - start}\n'
)
return result
return wrapper