Safemotion Lib
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
fastreid.utils.timer.Timer Class Reference

Public Member Functions

 __init__ (self)
 
 reset (self)
 
 pause (self)
 
bool is_paused (self)
 
 resume (self)
 
float seconds (self)
 
float avg_seconds (self)
 

Protected Attributes

 _start
 
 _total_paused
 
 _count_start
 
 _paused
 

Detailed Description

A timer which computes the time elapsed since the start/reset of the timer.

Definition at line 8 of file timer.py.

Constructor & Destructor Documentation

◆ __init__()

fastreid.utils.timer.Timer.__init__ ( self)

Definition at line 13 of file timer.py.

13 def __init__(self):
14 self.reset()
15

Member Function Documentation

◆ avg_seconds()

float fastreid.utils.timer.Timer.avg_seconds ( self)
Returns:
    (float): the average number of seconds between every start/reset and
    pause.

Definition at line 62 of file timer.py.

62 def avg_seconds(self) -> float:
63 """
64 Returns:
65 (float): the average number of seconds between every start/reset and
66 pause.
67 """
68 return self.seconds() / self._count_start

◆ is_paused()

bool fastreid.utils.timer.Timer.is_paused ( self)
Returns:
    bool: whether the timer is currently paused

Definition at line 33 of file timer.py.

33 def is_paused(self) -> bool:
34 """
35 Returns:
36 bool: whether the timer is currently paused
37 """
38 return self._paused is not None
39

◆ pause()

fastreid.utils.timer.Timer.pause ( self)
Pause the timer.

Definition at line 25 of file timer.py.

25 def pause(self):
26 """
27 Pause the timer.
28 """
29 if self._paused is not None:
30 raise ValueError("Trying to pause a Timer that is already paused!")
31 self._paused = perf_counter()
32

◆ reset()

fastreid.utils.timer.Timer.reset ( self)
Reset the timer.

Definition at line 16 of file timer.py.

16 def reset(self):
17 """
18 Reset the timer.
19 """
20 self._start = perf_counter()
21 self._paused: Optional[float] = None
22 self._total_paused = 0
23 self._count_start = 1
24

◆ resume()

fastreid.utils.timer.Timer.resume ( self)
Resume the timer.

Definition at line 40 of file timer.py.

40 def resume(self):
41 """
42 Resume the timer.
43 """
44 if self._paused is None:
45 raise ValueError("Trying to resume a Timer that is not paused!")
46 self._total_paused += perf_counter() - self._paused
47 self._paused = None
48 self._count_start += 1
49

◆ seconds()

float fastreid.utils.timer.Timer.seconds ( self)
Returns:
    (float): the total number of seconds since the start/reset of the
        timer, excluding the time when the timer is paused.

Definition at line 50 of file timer.py.

50 def seconds(self) -> float:
51 """
52 Returns:
53 (float): the total number of seconds since the start/reset of the
54 timer, excluding the time when the timer is paused.
55 """
56 if self._paused is not None:
57 end_time: float = self._paused # type: ignore
58 else:
59 end_time = perf_counter()
60 return end_time - self._start - self._total_paused
61

Member Data Documentation

◆ _count_start

fastreid.utils.timer.Timer._count_start
protected

Definition at line 23 of file timer.py.

◆ _paused

fastreid.utils.timer.Timer._paused
protected

Definition at line 31 of file timer.py.

◆ _start

fastreid.utils.timer.Timer._start
protected

Definition at line 20 of file timer.py.

◆ _total_paused

fastreid.utils.timer.Timer._total_paused
protected

Definition at line 22 of file timer.py.


The documentation for this class was generated from the following file: