Basic Usage¶
We’ll start by importing the (always existing) global pytimings.timer.Timings
object.
from pytimings.timer import global_timings
global_timings
<pytimings.timer.Timings at 0x7efbf8224b10>
To measure the execution time of a given code segment you can
start a timer with a given section name and stop it afterwards.
stop
returns a pytimings.timer.TimingsDelta
object with the gathered info.
global_timings.start("a_section_name")
...
global_timings.stop("a_section_name")
TimingDelta(wall=0.000172274, sys=0.0, user=0.0)
To inspect deltas of known sections at any other point
use the pytimings.timer.Timings.delta()
function.
global_timings.delta("a_section_name")
TimingDelta(wall=0.000172274, sys=0.0, user=0.0)
There’s also a convenience method pytimings.timer.Timings.walltime()
to only query the walltime instead of the full delta object.
To get an overview over all sections you can use {meth}
pytimings.timer.Timings.output_console`.
global_timings.output_console()
Section Walltime (HH:MM:SS) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ a_section_name 0:00:00.000172