import random
import time
def download(filename):
print(f'开始下载{filename}')
time.sleep(random.randint(2, 6))
print(f'{filename}下载完成')
def upload(filename):
print(f'开始上传{filename}')
time.sleep(random.randint(4, 8))
print(f'{filename}上传完成')
start = time.time()
end = time.time()
print(f'花费时间:{end - start:.3f}秒')
start = time.time()
end = time.time()
print(f'花费时间:{end - start:.3f}秒')
def record_time(func):
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print(f'{func.__name__}执行时间:{end - start:.3f}秒')
return result
return wrapper
download = record_time(download)
download('JAVA教学.avi')
@record_time
def download(filename):
print(f'开始下载{filename}')
time.sleep(random.randint(1, 3))
print(f'{filename}下载完成')
@record_time
def upload(filename):
print(f'开始上传{filename}')
time.sleep(random.randint(1, 3))
print(f'{filename}上传完成')
download('Mysql从删库到跑路.avi')
upload('Py从入门到入土.pdf')
|