TimerOutputs.jl : How to correctly stop timing?

Hi all!

I have a need to “freeze” a timer object and ensure that it stops counting the time. I have the following example code:

using TimerOutputs

# Create a new timer object
const MyTimer = TimerOutput()

function simulation_step1()
    @timeit MyTimer "Step 1" sleep(0.1)  # Simulating a computation-heavy task
end

function simulation_step2()
    @timeit MyTimer "Step 2" sleep(0.2)  # Simulating a longer computation-heavy task
end

function simulation_step3()
    @timeit MyTimer "Step 3" sleep(0.05)  # Simulating a shorter computation-heavy task
end

function run_simulation()
    simulation_step1()
    simulation_step2()
    simulation_step3()
end

run_simulation()

println(MyTimer)
disable_timer!(MyTimer)
sleep(5)
println(MyTimer)

Which produces:

image

Using disable_timer! it seems to correctly stop the inner timers so that they do not add up, but the “global” time is still counting.

How do I enforce/completely pause any tracking for a specific timer?

Kind regards

For anyone looking in the future, seems like it has been on the roadmap, but not possible to do unfortunately.

1 Like