Skip to content

Instantly share code, notes, and snippets.

@kokospapa8
Created June 27, 2018 11:41
Show Gist options
  • Select an option

  • Save kokospapa8/f07a4a16b610032e94e87e6946d6ca2f to your computer and use it in GitHub Desktop.

Select an option

Save kokospapa8/f07a4a16b610032e94e87e6946d6ca2f to your computer and use it in GitHub Desktop.
Time measure decorator for coroutine
```
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
```
@MJ111
Copy link

MJ111 commented Jun 27, 2018

cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment