def timethis(what):
@contextlib.contextmanager<EOL>def benchmark():<EOL><INDENT>timer = time.clock if sys.platform == "<STR_LIT:win32>" else time.time<EOL>start = timer()<EOL>yield<EOL>stop = timer()<EOL>res = (stop - start)<EOL>print_bench(what, res, "<STR_LIT>")<EOL><DEDENT>if hasattr(what, "<STR_LIT>"):<EOL><INDENT>def timed(*args, **kwargs):<EOL><INDENT>with benchmark():<EOL><INDENT>return what(*args, **kwargs)<EOL><DEDENT><DEDENT>return timed<EOL><DEDENT>else:<EOL><INDENT>return benchmark()<EOL><DEDENT>
Utility function for making simple benchmarks (calculates time calls).
    It can be used either as a context manager or as a decorator.