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

**URL:** https://discourse.julialang.org/t/save-information-in-timeroutput-timeroutputs-jl-as-a-dataframe/102774
**Category:** General Usage
**Created:** [August 13, 2023, 6:05pm UTC](https://discourse.julialang.org/t/save-information-in-timeroutput-timeroutputs-jl-as-a-dataframe/102774 "2023-08-13T18:05:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Martin](https://discourse.julialang.org/u/Martin)
#### Post date: [August 13, 2023, 6:05pm UTC](https://discourse.julialang.org/t/save-information-in-timeroutput-timeroutputs-jl-as-a-dataframe/102774/1 "2023-08-13T18:05:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)
#### Post date: [August 14, 2023, 1:02pm UTC](https://discourse.julialang.org/t/save-information-in-timeroutput-timeroutputs-jl-as-a-dataframe/102774/2 "2023-08-14T13:02:54Z")

</div>

> [@Martin](#):
>
> a convenient way to save these numbers into a data structure that is easier to do some statistics on

I’ve seen this snippet somewhere:

```julia
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.

---

<div class="post-metadata">

### Author: ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)
#### Post date: [August 14, 2023, 1:25pm UTC](https://discourse.julialang.org/t/save-information-in-timeroutput-timeroutputs-jl-as-a-dataframe/102774/3 "2023-08-14T13:25:43Z")

</div>

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