Skip to content

Instantly share code, notes, and snippets.

@qpleple
Created February 28, 2014 11:15
Show Gist options
  • Save qpleple/9269339 to your computer and use it in GitHub Desktop.
Save qpleple/9269339 to your computer and use it in GitHub Desktop.
Time function execution in Python
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