Shortcuts

Timer

class mmengine.utils.Timer(start=True, print_tmpl=None)[source]

A flexible Timer class.

Examples

>>> import time
>>> import mmcv
>>> with mmcv.Timer():
>>>     # simulate a code block that will run for 1s
>>>     time.sleep(1)
1.000
>>> with mmcv.Timer(print_tmpl='it takes {:.1f} seconds'):
>>>     # simulate a code block that will run for 1s
>>>     time.sleep(1)
it takes 1.0 seconds
>>> timer = mmcv.Timer()
>>> time.sleep(0.5)
>>> print(timer.since_start())
0.500
>>> time.sleep(0.5)
>>> print(timer.since_last_check())
0.500
>>> print(timer.since_start())
1.000
property is_running

indicate whether the timer is running

Type:

bool

since_last_check()[source]

Time since the last checking.

Either since_start() or since_last_check() is a checking operation.

Returns:

Time in seconds.

Return type:

float

since_start()[source]

Total time since the timer is started.

Returns:

Time in seconds.

Return type:

float

start()[source]

Start the timer.