mirror of
https://github.com/Balshgit/different
synced 2025-09-11 02:50:41 +03:00
change execution_time decorator
This commit is contained in:
parent
a99094e6b1
commit
e98ab90991
@ -13,25 +13,30 @@ def func_exec_count(func):
|
|||||||
return new_func
|
return new_func
|
||||||
|
|
||||||
|
|
||||||
def execution_time(func):
|
def execution_time(time_form='sec'):
|
||||||
@wraps(func)
|
multiply = {'sec': 1, 'min': 60, 'hour': 3600}
|
||||||
def exec_func(*args, **kwargs):
|
|
||||||
now = datetime.now()
|
def wrapper(func):
|
||||||
func_result = func(*args, **kwargs)
|
@wraps(func)
|
||||||
end = datetime.now()
|
def new_func(*args, **kwargs):
|
||||||
print('time to execute', (end - now).seconds)
|
begin = datetime.now()
|
||||||
return func_result
|
result = func(*args, **kwargs)
|
||||||
return exec_func
|
end = datetime.now()
|
||||||
|
exec_time = (end - begin).seconds / multiply[time_form]
|
||||||
|
print(f'Duration, {time_form}: {exec_time}')
|
||||||
|
return result
|
||||||
|
return new_func
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
@func_exec_count
|
@func_exec_count
|
||||||
@execution_time
|
@execution_time()
|
||||||
def summary(x: int, y: int) -> int:
|
def summary(x: int, y: int) -> int:
|
||||||
z = x + y
|
z = x + y
|
||||||
return z
|
return z
|
||||||
|
|
||||||
|
|
||||||
@execution_time
|
@execution_time(time_form='min')
|
||||||
def main():
|
def main():
|
||||||
result = 0
|
result = 0
|
||||||
for i in range(1, 11):
|
for i in range(1, 11):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user