# ANN: TimerOutputs.jl

**URL:** https://discourse.julialang.org/t/ann-timeroutputs-jl/2429
**Category:** Community
**Tags:** package, announcement
**Created:** [March 3, 2017, 9:37pm UTC](https://discourse.julialang.org/t/ann-timeroutputs-jl/2429 "2017-03-03T21:37:50Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [December 2, 2017, 1:26am UTC](https://discourse.julialang.org/t/ann-timeroutputs-jl/2429/3 "2017-12-02T01:26:20Z")

</div>

I recently added (and tagged) functionality to annotate function definitions. This is sometimes more convenient than adding them at the call site or surrounding a whole function block with the macro. Annotating a function definition is done with the same `@timeit` macro and this will record a section with the same name as the function when the function is called.

For example:

```julia
julia> using TimerOutputs

julia> const to = TimerOutput();

julia> @timeit to f(x) = x
f (generic function with 1 method)

julia> @timeit to function g(x)
           # Doing stuff
           return sin(x)
       end
g (generic function with 1 method)

julia> for i in 1:100 f(2) end;

julia> for j in 1:10 g(2.0) end;

julia> to
 ──────────────────────────────────────────────────────────────────
                           Time Allocations
                   ────────────────────── ───────────────────────
 Tot / % measured: 9.39s / 0.00% 1.08MiB / 0.00%

 Section ncalls time %tot avg alloc %tot avg
 ──────────────────────────────────────────────────────────────────
 f 100 5.15μs 75.2% 51.5ns - - % -
 g 10 1.70μs 24.8% 170ns - - % -
 ──────────────────────────────────────────────────────────────────

```

The timer `to` can be left out and the global one will be used in that case:

```julia
julia> @timeit h(x) = x
h (generic function with 1 method)

julia> h(2)
2

julia> print_timer()
 ──────────────────────────────────────────────────────────────────
                           Time Allocations
                   ────────────────────── ───────────────────────
 Tot / % measured: 3.88s / 0.00% 289KiB / 0.00%

 Section ncalls time %tot avg alloc %tot avg
 ──────────────────────────────────────────────────────────────────
 h 1 295ns 100% 295ns - - % -
 ──────────────────────────────────────────────────────────────────

```

Happy timing!

---

_[View the full topic](https://discourse.julialang.org/t/ann-timeroutputs-jl/2429)._
