MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / timed_operation

Function timed_operation

tensorpack/utils/timer.py:18–45  ·  view source on GitHub ↗

Surround a context with a timer. Args: msg(str): the log to print. log_start(bool): whether to print also at the beginning. Example: .. code-block:: python with timed_operation('Good Stuff'): time.sleep(1) Will print:

(msg, log_start=False)

Source from the content-addressed store, hash-verified

16
17@contextmanager
18def timed_operation(msg, log_start=False):
19 """
20 Surround a context with a timer.
21
22 Args:
23 msg(str): the log to print.
24 log_start(bool): whether to print also at the beginning.
25
26 Example:
27 .. code-block:: python
28
29 with timed_operation('Good Stuff'):
30 time.sleep(1)
31
32 Will print:
33
34 .. code-block:: python
35
36 Good stuff finished, time:1sec.
37 """
38 assert len(msg)
39 if log_start:
40 logger.info('Start {} ...'.format(msg))
41 start = timer()
42 yield
43 msg = msg[0].upper() + msg[1:]
44 logger.info('{} finished, time:{:.4f} sec.'.format(
45 msg, timer() - start))
46
47
48_TOTAL_TIMER_DATA = defaultdict(StatCounter)

Callers 3

loadMethod · 0.90
find_keysMethod · 0.85
get_training_bboxMethod · 0.85

Calls 1

formatMethod · 0.80

Tested by

no test coverage detected