Skip to main content

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

AttributeTypeDescription
recordsdict = 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

NameTypeDescription
namestringThe unique identifier or label used to group and store the timing results for the associated code block

Returns

TypeDescription
GeneratorA context manager that yields control to the wrapped block and records elapsed time upon exit

@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

TypeDescription
nullNone