Save information in TimerOutput (TimerOutputs.jl) as a DataFrame

Hi!

At the moment I am comparing different (in this case machine learning) algorithms in a project, and I am interested in the running time and memory allocations. So I have been using the great package TimerOutputs.jl to see these numbers, but now I would like to find a convenient way to save these numbers into a data structure that is easier to do some statistics on, like a DataFrame. Is there a simple way? Or should I perhaps be using some other way to track time and memory allocations?

In a small example I have, output looks like this:

─────────────────────────────────────────────────────────────────────────────
Time Allocations
─────────────────────── ────────────────────────
Tot / % measured: 8.84h / 0.3% 8.51GiB / 84.7%

Section ncalls time %tot avg alloc %tot avg
─────────────────────────────────────────────────────────────────────────────
euler-step 120 33.4s 39.1% 279ms 4.66GiB 64.6% 39.8MiB
knb calculate Y 120 29.0s 33.9% 242ms 1.43GiB 19.8% 12.2MiB
sc calculate Y 120 12.9s 15.1% 108ms 1.08GiB 15.0% 9.21MiB
sc 120 9.92s 11.6% 82.6ms 9.82MiB 0.1% 83.8KiB
knb 120 243ms 0.3% 2.02ms 11.9MiB 0.2% 101KiB
all trajectories 2 36.1ms 0.0% 18.0ms 24.1MiB 0.3% 12.1MiB
─────────────────────────────────────────────────────────────────────────────

and it seems like there could be some easy way to convert this to a DataFrame?

Best regards,
Martin Andersson

I’ve seen this snippet somewhere:

julia> function timer_namedtuple(to::TimerOutput, name="")
                  ks = sort!(collect(keys(to.inner_timers)))
                  return (;
                      name,
                      ncalls=TimerOutputs.ncalls(to),
                      time=TimerOutputs.time(to),
                      allocated=TimerOutputs.allocated(to),
                      totallocated=TimerOutputs.totallocated(to),
                      tottime=TimerOutputs.tottime(to),
                      inner_timers=[timer_namedtuple(to.inner_timers[k], k) for k in ks]
                  )
        end

It converts the timer into a plain julia collection of individual timings, potentially nested. Pretty convenient to work with using generic data processing tools.

TimerOutputs also has a documented TimerOutputs.todict function that does something similar but with Dict’s.