# Benchmark parts of a function?

**URL:** <https://discourse.julialang.org/t/benchmark-parts-of-a-function/63844>\
**Category:** New to Julia\
**Tags:** question, benchmark\
**Created:** [June 30, 2021, 4:47pm UTC](https://discourse.julialang.org/t/benchmark-parts-of-a-function/63844 "2021-06-30T16:47:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduardovrs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eduardovrs/32/20041_2.png) [@eduardovrs](https://discourse.julialang.org/u/eduardovrs)\
**Post date:** [June 30, 2021, 4:47pm UTC](https://discourse.julialang.org/t/benchmark-parts-of-a-function/63844/1 "2021-06-30T16:47:22Z")

</div>

Hello everyone,

I am trying to benchmark the operations inside a function to have an idea where would be best to focus to try to optimize, and at the moment I do something similar to:

```julia
function foo()
    a = @btime rand(100)
    b = @btime rand(100)
    c = @btime $a .* $b + $a
    d = @btime $c .+ $a
    bar = @btime $d .- $b
    return bar
end # foo

```

What would be a better way to do a similar benchmark?

Thanks in advance for the help 🙂 ,  
Eduardo

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [June 30, 2021, 4:54pm UTC](https://discourse.julialang.org/t/benchmark-parts-of-a-function/63844/2 "2021-06-30T16:54:51Z")

</div>

Profiling? [Profiling · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Profile/)

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [June 30, 2021, 6:01pm UTC](https://discourse.julialang.org/t/benchmark-parts-of-a-function/63844/3 "2021-06-30T18:01:40Z")

</div>

Profiling is possibly the right way. But also check out [GitHub - KristofferC/TimerOutputs.jl: Formatted output of timed sections in Julia](https://github.com/KristofferC/TimerOutputs.jl)

---

<div class="post-metadata">

**Author:** ![eduardovrs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eduardovrs/32/20041_2.png) [@eduardovrs](https://discourse.julialang.org/u/eduardovrs)\
**Post date:** [June 30, 2021, 7:37pm UTC](https://discourse.julialang.org/t/benchmark-parts-of-a-function/63844/4 "2021-06-30T19:37:21Z")

</div>

> [@PetrKryslUCSD](#):
>
> Profiling

Thank you, I remember reading the docs about it before but totally forgot. It looks like it is what I need.

> [@DNF](#):
>
> [TimerOutputs](https://github.com/KristofferC/TimerOutputs.jl)

Maybe I will try this too later. Thank you.
