decorator finished

This commit is contained in:
2025-03-19 17:51:14 +00:00
parent 00197cf3c5
commit a0795f56ab
2 changed files with 35 additions and 18 deletions

View File

@@ -1,20 +1,17 @@
#decorator
def my_decorator(func):
from time import time
def wrap_func():
print('************')
func()
print('************')
def performance(fn):
def wrapper(*args, **kwargs):
t1 = time()
result = fn(*args, **kwargs)
t2 = time()
print(f'took {t2-t1} ms')
return result
return wrapper
return wrap_func
@performance
def long_time():
for i in range(1000000):
i*5
@my_decorator
def hello():
print('hellllooooooooooo')
@my_decorator
def bye():
print('see ya letter')
hello()
bye()
long_time()

View File

@@ -109,3 +109,23 @@
for ex:
from time import time
def performance(fn):
def wrapper(*args, **kwargs):
t1 = time()
result = fn(*args, **kwargs)
t2 = time()
print(f'took {t2-t1} ms')
return result
return wrapper
@performance
def long_time():
for i in range(1000000):
i*5
long_time()