Skip to content

Instantly share code, notes, and snippets.

@SpotlightKid
Forked from mrocklin/duration.py
Created January 14, 2014 12:04
Show Gist options
  • Save SpotlightKid/8417289 to your computer and use it in GitHub Desktop.
Save SpotlightKid/8417289 to your computer and use it in GitHub Desktop.
from contextlib import contextmanager
from time import time
from sys import stdout
@contextmanager
def duration(outfile=stdout):
start = time()
yield
end = time()
outfile.write(str(end - start) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment