Skip to content

Instantly share code, notes, and snippets.

@TigerND
Last active May 20, 2016 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TigerND/77bc0af6ab266d074635ff58fdf76aa9 to your computer and use it in GitHub Desktop.
Save TigerND/77bc0af6ab266d074635ff58fdf76aa9 to your computer and use it in GitHub Desktop.
import datetime
from contextlib import contextmanager
@contextmanager
def elapsed_time():
t1 = datetime.datetime.now()
yield
t2 = datetime.datetime.now()
print(u'Elapsed time: %s' % (t2 - t1))
with elapsed_time():
print (2 + 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment