Timing Class#
The Timing
class is a utility class for managing timing profiling of the code.
Class Initialization#
The class is initialized without any arguments. The initialization process sets up a logger, records the start time, and initializes an empty dictionary to hold timers.
timing = Timing()
Methods#
start(timer_name: str)#
This method starts a timer with the given name. If the timer does not exist, it is created and its count is set to zero. If the timer is already running, an error message is logged.
timing.start('timer1')
stop(timer_name: str)#
This method stops a timer with the given name. If the timer does not exist or is not running, an error message is logged. The elapsed time is added to the total time of the timer.
timing.stop('timer1')
finalize()#
This method finalizes the timing measurements and logs the results. It checks that no timer is still running, calculates the total time, the time per count, and the percentage of total time for each timer, and logs this information.
timing.finalize()
Example Usage#
timing = Timing()
timing.start('timer1')
<Code to be timed goes here>
timing.stop('timer1')
timing.finalize()