gpt4free/etc/testing/log_time.py
ⲘrṨhส∂ow 3982f39424
'Refactored by Sourcery' (#1125)
Co-authored-by: Sourcery AI <>
2023-10-23 09:46:25 +02:00

21 lines
585 B
Python

from time import time
async def log_time_async(method: callable, **kwargs):
start = time()
result = await method(**kwargs)
secs = f"{round(time() - start, 2)} secs"
return " ".join([result, secs]) if result else secs
def log_time_yield(method: callable, **kwargs):
start = time()
result = yield from method(**kwargs)
yield f" {round(time() - start, 2)} secs"
def log_time(method: callable, **kwargs):
start = time()
result = method(**kwargs)
secs = f"{round(time() - start, 2)} secs"
return " ".join([result, secs]) if result else secs