Created
October 4, 2016 14:09
-
-
Save simahawk/6c470229c62c0738dc7c5fe995e8d001 to your computer and use it in GitHub Desktop.
time your python functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def timeit(method): | |
"""Decorate methods to measure time.""" | |
def timed(*args, **kw): | |
print 'START', method.__name__ | |
ts = time.time() | |
result = method(*args, **kw) | |
te = time.time() | |
print 'STOP', method.__name__ | |
print 'TIME %r (%r, %r) %2.2f sec' % \ | |
(method.__name__, args, kw, te - ts) | |
return result | |
return timed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment