Shortcuts

Timer

class mmengine.utils.Timer(start=True, print_tmpl=None)[源代码]

A flexible Timer class.

示例

>>> 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()[源代码]

Time since the last checking.

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

返回:

Time in seconds.

返回类型:

float

since_start()[源代码]

Total time since the timer is started.

返回:

Time in seconds.

返回类型:

float

start()[源代码]

Start the timer.