Every line of 'timer decorator python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
14 def gtimer_wrapped_arg(func): 15 return inner_wrap(func, *args, **kwargs)
21 def _timer(func): 22 @wraps(func) 23 def wrapper(*args, **kwargs): # passing params to func 24 s_time = time.time() 25 func(*args, **kwargs) 26 e_time = time.time() 27 period = (e_time-s_time) / 60 28 print(info + '-> elapsed time: %.3f minutes' % period) 29 return wrapper
142 @functools.wraps(f) 143 def wrapper(*args, **kwds): 144 start = time.time() 145 result = f(*args, **kwds) 146 elapsed = time.time() - start 147 sys.stderr.write("{} took {:.4f}s to finish\n".format(f.__name__, elapsed)) 148 return result
31 @staticmethod 32 def _timer(func): 33 """ 34 Timing decorator 35 """ 36 def wrapper(*args, **kwargs): 37 """ 38 Wrap timing and message printing 39 """ 40 tstart = int(time.time()) 41 ret = func(*args, **kwargs) 42 time_delta = int(time.time()) - tstart 43 app.logger.debug("%s took %d seconds" % 44 (func.__name__, time_delta)) 45 return ret 46 return wrapper
26 def outer(func): 27 @functools.wraps(func) 28 def inner(*args): 29 """Decorator to time function execution. 30 31 If an exception is raised during the function, then a time of "-1" 32 will be saved for the given description. 33 34 Note: Any function decorated with this should have the "stats" dict 35 as the final argument in its arg list. 36 37 """ 38 # Setup. 39 stats = args[-1] 40 stats[desc] = -1 41 start = time.time() 42 43 # Execute the function. 44 ret_val = func(*args) 45 46 # No exception, so save the runtime and return ret_val. 47 stats[desc] = time.time() - start 48 return ret_val 49 return inner
14 def test_decorator(self): 15 timeit = timer() 16 17 @timeit 18 def foo(): 19 os.getcwd() 20 21 foo() 22 assert timeit.elapsed is not None
17 def f_timer(*args, **kwargs): 18 start = time.time() 19 result = f(*args, **kwargs) 20 end = time.time() 21 print '====================================================' 22 print f.__name__, 'took', '%.4f' % (end - start), 'seconds' 23 print '====================================================' 24 return result