Created
June 27, 2018 11:41
-
-
Save kokospapa8/f07a4a16b610032e94e87e6946d6ca2f to your computer and use it in GitHub Desktop.
Time measure decorator for coroutine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ``` | |
| from sanic.log import logger | |
| from insanic.conf import settings | |
| from functools import wraps | |
| from time import time | |
| def measure_time(f): | |
| @wraps(f) | |
| async def wrapper(*args, **kwargs): | |
| #make sure you run this on non-prod env | |
| start_time = time() | |
| result = await f(*args, **kwargs) | |
| #make sure you run this on non-prod env | |
| logger.debug(f"Elapsed time for {f.__name__}: {time() - start_time}") | |
| return result | |
| return wrapper | |
| ``` | |
| ``` | |
| #usage | |
| @measure_time | |
| async def test_coro(id) -> list: | |
| pass | |
| ``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool