Skip to content

Instantly share code, notes, and snippets.

@etale-cohomology
Created March 10, 2016 04: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 etale-cohomology/7d39dc5a29e56a62798a to your computer and use it in GitHub Desktop.
Save etale-cohomology/7d39dc5a29e56a62798a to your computer and use it in GitHub Desktop.
@contextlib.contextmanager # Create factory function for *with* context managers
def timeit():
"""Time execution of code, based on time.clock(). Call using a *with* statement!
Examples:
with timeit():
a @ a
"""
start = time.clock()
yield # The decorated func must return a generator-iterator
print('Operation took: %0.6f seconds!' % (time.clock() - start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment