summaryrefslogtreecommitdiffstats
path: root/etc/testing/log_time.py
blob: 376ab86da0108cbc5bae0240c84d5b27bfd8c5a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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"
    if result:
        return " ".join([result, secs])
    return 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"
    if result:
        return " ".join([result, secs])
    return secs