TimeKeeper
This class provides a mechanism for measuring and recording the execution time of code blocks using a context manager. It stores multiple timing records for labeled operations and includes a utility to output these results to the standard error stream.
Attributes
| Attribute | Type | Description |
|---|---|---|
| records | dict = collections.defaultdict(list) | A dictionary mapping task names to lists of elapsed execution times recorded during timed context blocks. |
Constructor
Signature
def TimeKeeper() - > null
Signature
def TimeKeeper() - > null
Methods
timed()
@classmethod
def timed(
name: string
) - > Generator
Measures the execution time of a code block using a context manager and stores the result under the specified label.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The unique identifier or label used to group and store the timing results for the associated code block |
Returns
| Type | Description |
|---|---|
Generator | A context manager that yields control to the wrapped block and records elapsed time upon exit |
print_results()
@classmethod
def print_results() - > null
Iterates through all recorded timing data and writes the formatted duration for each entry to the standard error stream.
Returns
| Type | Description |
|---|---|
null | None |