@contextmanager
def time_block(message):
 tic = time.time()
 (yield)
 dt = (time.time() - tic)
 log = (app_log.info if (dt > 1) else app_log.debug)
 log('%s in %.2f ms', message, (1000.0 * dt))

@ contextmanager def time_block ( message ) : tic = time . time ( ) ( yield ) dt = ( time . time ( ) - tic ) log = ( app_log . info if ( dt > 1 ) else app_log . debug ) log ( '%s in %.2f ms' , message , ( 1000.0 * dt ) )
context manager for timing a block logs millisecond timings of the block .