memoryscope.core.utils.timer
- class memoryscope.core.utils.timer.Timer(name: str, time_log_type: Literal['end', 'wrap', 'none'] = 'end', use_ms: bool = True, stack_level: int = 2, float_precision: int = 4, **kwargs)[source]
Bases:
object
A class used to measure the execution time of code blocks. It supports logging the elapsed time and can be customized to display time in seconds or milliseconds.
- __init__(name: str, time_log_type: Literal['end', 'wrap', 'none'] = 'end', use_ms: bool = True, stack_level: int = 2, float_precision: int = 4, **kwargs)[source]
Initializes the Timer instance with the provided args and sets up a logger
- Parameters:
name (str) – The log name.
time_log_type (str) – The log type. Defaults to ‘End’.
use_ms (bool) – Use ‘ms’ as the timescale or not. Defaults to True.
stack_level (int) – The stack level of log. Defaults to 2.
float_precision (int) – The precision of cost time. Defaults to 4.
- property cost_str
Represent the cost time into a formatted string.