
    9i                     D    S SK J r    " S S\5      r " S S5      r0 rS rg)    )timec                   (   ^  \ rS rSrU 4S jrSrU =r$ )
TimerError   c                 8   > Xl         [        [        U ]  U5        g N)messagesuperr   __init__)selfr	   	__class__s     a/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/preprocessors/cv/timer.pyr   TimerError.__init__	   s    j$(1    )r	   )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r   r      s    2 2r   r   c                   P    \ rS rSrSrSS jr\S 5       rS rS r	S r
S	 rS
 rSrg)Timer   a  A flexible Timer class.
Example:

>>> 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
Nc                 b    SU l         U(       a  UOSU l        U(       a  U R                  5         g g )NFz{:.3f})_is_running
print_tmplstart)r   r   r   s      r   r   Timer.__init__'   s&     (2*JJL r   c                     U R                   $ )z+bool: indicate whether the timer is running)r   r   s    r   
is_runningTimer.is_running-   s     r   c                 &    U R                  5         U $ r   )r   r    s    r   	__enter__Timer.__enter__2   s    

r   c                 v    [        U R                  R                  U R                  5       5      5        SU l        g )NF)printr   formatsince_last_checkr   )r   typevalue	tracebacks       r   __exit__Timer.__exit__6   s*    doo$$T%:%:%<=> r   c                 p    U R                   (       d  [        5       U l        SU l         [        5       U l        g)zStart the timer.TN)r   r   _t_start_t_lastr    s    r   r   Timer.start:   s%     FDM#Dvr   c                     U R                   (       d  [        S5      e[        5       U l        U R                  U R                  -
  $ )zITotal time since the timer is started.
Returns (float): Time in seconds.
timer is not running)r   r   r   r1   r0   r    s    r   since_startTimer.since_startA   s5     344v||dmm++r   c                     U R                   (       d  [        S5      e[        5       U R                  -
  n[        5       U l        U$ )zTime since the last checking.
Either :func:`since_start` or :func:`since_last_check` is a checking
operation.
Returns (float): Time in seconds.
r4   )r   r   r   r1   )r   durs     r   r)   Timer.since_last_checkJ   s7     344ft||#v
r   )r   r1   r0   r   )TN)r   r   r   r   __doc__r   propertyr!   r$   r-   r   r5   r)   r    r   r   r   r      s9    0    !,
r   r   c                 h    U [         ;  a  [        5       [         U '   g[         U    R                  5       $ )a  Add check points in a single line.
This method is suitable for running a task on a list of items. A timer will
be registered when the method is called for the first time.
Example:

>>> import time
>>> import mmcv
>>> for i in range(1, 6):
>>>     # simulate a code block
>>>     time.sleep(i)
>>>     mmcv.check_time('task1')
2.000
3.000
4.000
5.000
Args:
    timer_id (str): Timer identifier.
r   )	_g_timersr   r)   )timer_ids    r   
check_timer@   Z   s/    & y #g	("3355r   N)r   	Exceptionr   r   r>   r@   r<   r   r   <module>rB      s/    2 2F FR 	6r   