# How can I use TimerOutputs.jl to time a function and its internal function calls in a package?

**URL:** https://discourse.julialang.org/t/how-can-i-use-timeroutputs-jl-to-time-a-function-and-its-internal-function-calls-in-a-package/106702
**Category:** Performance
**Tags:** performance, timeroutputs
**Created:** [November 25, 2023, 8:54am UTC](https://discourse.julialang.org/t/how-can-i-use-timeroutputs-jl-to-time-a-function-and-its-internal-function-calls-in-a-package/106702 "2023-11-25T08:54:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)
#### Post date: [November 25, 2023, 8:54am UTC](https://discourse.julialang.org/t/how-can-i-use-timeroutputs-jl-to-time-a-function-and-its-internal-function-calls-in-a-package/106702/1 "2023-11-25T08:54:30Z")

</div>

From the doc of the TimerOutputs.jl, it is not clear how to use it for timing a function and its internal function calls in my developing packages. Normally, I will create a new environment outside of my package and write a script, such as

```julia
using TimerOutputs
using MyPackage

const to = TimerOutput()
@timeit to "myfunc" MyPackage.myfunc()

```

However, this code can only report the time cost by `myfunc`. I also want to time all internal function calls inside `myfunc`. How can I do that? Shall I pass `to` as an argument for `myfunc`. Even worse, this approach will also introduce an extra dependency of TimerOutputs to MyPackage. Is there any less obtrusive way to do so?

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [November 25, 2023, 10:00am UTC](https://discourse.julialang.org/t/how-can-i-use-timeroutputs-jl-to-time-a-function-and-its-internal-function-calls-in-a-package/106702/2 "2023-11-25T10:00:23Z")

</div>

Haven’t tried it myself, but looking at the linked docs it looks like you’d need to expand the macro on the nested calls to time them.

> [@liuyxpp](#):
>
> Even worse, this approach will also introduce an extra dependency of TimerOutputs to MyPackage. Is there any less obtrusive way to do so?

If it weren’t for the nested macros, this sounds like [stacking](https://jkrumbiegel.com/pages/2022-08-26-pkg-introduction/#stacked-environments) the package in an environment with TimerOutputs or working in separate environment adding TimerOutputs and MyPackage. But maybe you’ll need to do this in a [“test” subdirectory](https://pkgdocs.julialang.org/v1/creating-packages/#Test-specific-dependencies) with TimerOutputs as a specific dependency.
