def timing(rounds=<NUM_LIT:1>, limit=None):
def decorator(method):<EOL><INDENT>@functools.wraps(method)<EOL>def f():<EOL><INDENT>if rounds == <NUM_LIT:1>:<EOL><INDENT>start = time.time()<EOL>method()<EOL>duration = time.time() - start<EOL><DEDENT>else:<EOL><INDENT>start = time.time()<EOL>for i in range(rounds):<EOL><INDENT>method()<EOL><DEDENT>duration = (time.time() - start) / rounds<EOL><DEDENT>duration = duration * <NUM_LIT><EOL>print('<STR_LIT>' % (method.__module__, method.__name__, duration))<EOL>if limit is not None:<EOL><INDENT>assert limit > duration, '<STR_LIT>' % (duration, limit)<EOL><DEDENT><DEDENT>if environ.get('<STR_LIT>', None) == '<STR_LIT:1>':<EOL><INDENT>return f<EOL><DEDENT>return method<EOL><DEDENT>return decorator<EOL>
Wrapper to implement simple timing of tests.
Allows running multiple rounds to calculate average time.
Limit (in milliseconds) can be set to assert, if (average) duration is too high.