Skip to content

Instantly share code, notes, and snippets.

@alonho
Last active December 10, 2015 21:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alonho/4493079 to your computer and use it in GitHub Desktop.
Save alonho/4493079 to your computer and use it in GitHub Desktop.
a timed contextmanager for easy benchmarking.
from Framework.Log.Log import logger
from contextlib import contextmanager
from time import time
@contextmanager
def timed(message):
''''
with timed('testing division'):
4 / 2
''''
stime = time()
yield
logger.info("{} took {}".format(message, time() - stime))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment