def print_timing(msg=None, debug=False):
 prefix = msg
 if isinstance(msg, types.FunctionType):
  prefix = msg.func_name
 def wrap_f(func, *arg, **kargs):
  'Raw timing function '
  time1 = time.time()
  res = func(*arg, **kargs)
  time2 = time.time()
  msg = ('%s took %0.3f mins' % (prefix, ((time2 - time1) / 60.0)))
  if debug:
   log.debug(msg)
  else:
   log.info(msg)
  return res
 if isinstance(msg, types.FunctionType):
  return decorator.decorator(wrap_f, msg)
 else:
  return decorator.decorator(wrap_f)

def print_timing ( msg = None , debug = False ) : prefix = msg if isinstance ( msg , types . FunctionType ) : prefix = msg . func_name def wrap_f ( func , * arg , ** kargs ) : time1 = time . time ( ) res = func ( * arg , ** kargs ) time2 = time . time ( ) msg = ( '%s took %0.3f mins' % ( prefix , ( ( time2 - time1 ) / 60.0 ) ) ) if debug : log . debug ( msg ) else : log . info ( msg ) return res if isinstance ( msg , types . FunctionType ) : return decorator . decorator ( wrap_f , msg ) else : return decorator . decorator ( wrap_f )
decorator for printing execution time of a function optionally takes a user-friendly msg as argument .