Disable TimerOutputs.jl timers selectively within function

I have a function that internally uses TimerOutputs.jl to time some calls to other functions. Sometimes, however, I want to be able to call this function without having the timers record anything, e.g., when I call the function outside it regular timer hierarchy.

What would be the best way to achieve this (assuming it is not possible with the shipped features of TimerOutputs.jl)? Is it easy enough to write a macro that disables @timeit macros in the functions it calls? Or should I define a new macro (e.g., @timeit_select) that I can turn on and off with yet a different macro? Sorry, I am too new to Julia to figure out what the Julian way of achieving this would be, so any help is appreciated.

P.S.: @kristoffer.carlsson Thanks for the great library! Coming from years of HPC software development with C++, I wish I had something as intuitive like TimerOutputs.jl back then…

1 Like

I think the easiest would be to add a flag to the TimerOutput struct itself and then check that flag in

https://github.com/KristofferC/TimerOutputs.jl/blob/2ad55c0ffffbf820c6be1d7b4077499c53bfb79d/src/TimerOutput.jl#L218-L244.

You would then disable / enable it with disable!(to) or enable!(to) or such.

TimerOutputs.jl is actually heavily inspired from a C++ implementation: The deal.II Library: TimerOutput Class Reference

1 Like

I understand your idea. Would you accept a PR for a possible implementation? It would probably need some guidance, though, since I have have only very little experience with macros and quoted expressions.

Yeah, sure. It should be a fairly small change I think.