Benchmark parts of a function?

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:

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 :slight_smile: ,
Eduardo

Profiling? Profiling ยท The Julia Language

4 Likes

Profiling is possibly the right way. But also check out GitHub - KristofferC/TimerOutputs.jl: Formatted output of timed sections in Julia

3 Likes

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

Maybe I will try this too later. Thank you.