def timefunc(num_tries=1, verbose=True):
 def real_decorator(function):
  @wraps(function)
  def wrapper(*args, **kwargs):
   ts = time.time()
   for i in range(num_tries):
    result = function(*args, **kwargs)
   te = time.time()
   tt = ((te - ts) / num_tries)
   if verbose:
    log.info(u'{0} took {1} s on AVERAGE for {2} call(s).'.format(function.__name__, tt, num_tries))
   return (tt, result)
  return wrapper
 return real_decorator

def timefunc ( num_tries = 1 , verbose = True ) : def real_decorator ( function ) : @ wraps ( function ) def wrapper ( * args , ** kwargs ) : ts = time . time ( ) for i in range ( num_tries ) : result = function ( * args , ** kwargs ) te = time . time ( ) tt = ( ( te - ts ) / num_tries ) if verbose : log . info ( u'{0} took {1} s on AVERAGE for {2} call(s).' . format ( function . __name__ , tt , num_tries ) ) return ( tt , result ) return wrapper return real_decorator
decorator that logs how long a particular function took to execute .