Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
calculate python function time
class Timeit(object):
def __init__(self, tag):
self.tag = tag
def __enter__(self):
self.start = time.time()
def __exit__(self, *unused):
self.cost = time.time() - self.start"%s took about: %ss" % (self.tag, self.cost))
def exec_profile(tag):
def warpper(func):
def new(*args, **kwds):
with Timeit(tag):
return func(*args, **kwds)
return new
return warpper
@exec_profile("sync device")
def syncer():
with as cursor:
cursor.execute("select hash from waf where hash IS NOT NULL")
self.devices = map(operator.itemgetter("hash"), cursor.fetchall())"current device number: {0}".format(self.devices))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.