Timer
Timer(precision: int = 5, desc: str = None, verbose: bool = False)
-
Description: This is a timer that can be used to measure the execution time of a program. The timer has three usage modes:
- using the
tic
andtoc
methods; - using decorators;
- using the
with
statement.
- using the
-
Parameters:
- precision (
int
): The precision of decimal points. Default is 5. - desc (
str
): Description text. Default is None. - verbose (
bool
): Whether to display the timing results. Default is False.
- precision (
-
Methods:
- tic(): Start the timer.
- toc(verbose=False): Stop the timer and return the elapsed time.
- clear_record(): Clear the records.
-
Attributes:
- mean (
float
): Mean time. - max (
float
): Maximum time. - min (
float
): Minimum time. - std (
float
): Standard deviation.
- mean (
-
Example:
import docsaidkit as D
# Using 'tic' and 'toc' method
t = D.Timer()
t.tic()
time.sleep(1)
t.toc()
# Using decorator
@D.Timer()
def testing_function():
time.sleep(1)
# Using 'with' statement
with D.Timer():
time.sleep(1)