Time each line of a code

Hello,

Is there a way to time each line of a function without having to write @time in front of each line. I am trying to figure out what are the slowest parts of my code.

1 Like

If you’re using Juno you can put @profiler in front of a call and it will track the time spent in each function (and the ones called by those, etc.). It also has a really nice display that shows the distribution of where the time is spent.

See more docs and a screenshot here:
http://docs.junolab.org/latest/man/juno_frontend/#Juno.@profiler

2 Likes

Thank you for your answer. I am more familiar with Jupyter. There is the package ProfileView I can use in IJulia, but how do you get the real time spent for each line and not just the flame diagram.

how do you get the real time spent for each line and not just the flame diagram

I am trying to figure out what are the slowest parts of my code.

The flame diagram gives you the relative time spent in every part of your code, so it definitely tells you which is the slowest part. Why do you want to put an absolute number on it?

(If you must, you can just multiply the total time spent by the fraction of the flamegraph spent in the function you are wondering about. But I don’t see how that helps you.)

Edit: if you are content with relative time, you could use StatProfilerHTML for a line-by-line view. I haven’t tried if it works well with Jupyter.

1 Like

Thank you

In addition to profiling as suggested by @ssfrr, I often find

useful.

3 Likes