Skip to content

Instantly share code, notes, and snippets.

@ericflo
Created July 2, 2010 18:35
Show Gist options
  • Save ericflo/461715 to your computer and use it in GitHub Desktop.
Save ericflo/461715 to your computer and use it in GitHub Desktop.
import time
from contextlib import contextmanager
@contextmanager
def easyprofile(msg):
before = time.time()
yield
print '%s took %0.2fsec' % (msg, time.time() - before)
if __name__ == '__main__':
with easyprofile('Executing an expensive query'):
results = get_expensive_data()
# Do something with the results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment