mirror of
https://github.com/Balshgit/different
synced 2025-09-11 02:50:41 +03:00
decorators added
This commit is contained in:
parent
f377b52acf
commit
d04553e621
43
decorators.py
Normal file
43
decorators.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import datetime
|
||||||
|
from functools import wraps
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
def func_exec_count(func):
|
||||||
|
@wraps(func)
|
||||||
|
def new_func(*args, **kwargs):
|
||||||
|
func_result = func(*args, **kwargs)
|
||||||
|
new_func.count += 1
|
||||||
|
return func_result
|
||||||
|
new_func.count = 0
|
||||||
|
return new_func
|
||||||
|
|
||||||
|
|
||||||
|
def execution_time(func):
|
||||||
|
@wraps(func)
|
||||||
|
def exec_func(*args, **kwargs):
|
||||||
|
now = datetime.now()
|
||||||
|
func_result = func(*args, **kwargs)
|
||||||
|
end = datetime.now()
|
||||||
|
print('time to execute', (end - now).seconds)
|
||||||
|
return func_result
|
||||||
|
return exec_func
|
||||||
|
|
||||||
|
|
||||||
|
@func_exec_count
|
||||||
|
@execution_time
|
||||||
|
def summary(x: int, y: int) -> int:
|
||||||
|
z = x + y
|
||||||
|
return z
|
||||||
|
|
||||||
|
|
||||||
|
@execution_time
|
||||||
|
def main():
|
||||||
|
result = 0
|
||||||
|
for i in range(1, 11):
|
||||||
|
result += summary(i, 100)
|
||||||
|
print(result)
|
||||||
|
print(summary.count, summary.__name__)
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
Loading…
x
Reference in New Issue
Block a user