Created
February 28, 2014 11:15
-
-
Save qpleple/9269339 to your computer and use it in GitHub Desktop.
Time function execution in Python
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 | |
from termcolor import colored | |
def chrono(method): | |
def timed(*args, **kw): | |
start = time.time() | |
result = method(*args, **kw) | |
print colored("%.3f" % (time.time() - start,), "yellow") + " sec,", | |
print colored(method.__name__, "green") + colored('%r' % (args,), "grey") | |
return result | |
return timed | |
if __name__ == '__main__': | |
@chrono | |
def mafonction(arg1, arg2): | |
time.sleep(2) | |
mafonction(12, "lkjfksdljf lsdk fjlsd flk jsd") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment