# Time each line of a code

**URL:** <https://discourse.julialang.org/t/time-each-line-of-a-code/36559>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 26, 2020, 4:50pm UTC](https://discourse.julialang.org/t/time-each-line-of-a-code/36559 "2020-03-26T16:50:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [March 26, 2020, 4:50pm UTC](https://discourse.julialang.org/t/time-each-line-of-a-code/36559/1 "2020-03-26T16:50:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [March 26, 2020, 5:06pm UTC](https://discourse.julialang.org/t/time-each-line-of-a-code/36559/2 "2020-03-26T17:06:10Z")

</div>

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](http://docs.junolab.org/latest/man/juno_frontend/#Juno.@profiler)

---

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [March 26, 2020, 5:44pm UTC](https://discourse.julialang.org/t/time-each-line-of-a-code/36559/3 "2020-03-26T17:44:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [March 26, 2020, 5:55pm UTC](https://discourse.julialang.org/t/time-each-line-of-a-code/36559/4 "2020-03-26T17:55:19Z")

</div>

> 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](https://github.com/tkluck/StatProfilerHTML.jl) for a line-by-line view. I haven’t tried if it works well with Jupyter.

---

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [March 26, 2020, 7:45pm UTC](https://discourse.julialang.org/t/time-each-line-of-a-code/36559/5 "2020-03-26T19:45:56Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 27, 2020, 6:46am UTC](https://discourse.julialang.org/t/time-each-line-of-a-code/36559/6 "2020-03-27T06:46:53Z")

</div>

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

> **[GitHub - KristofferC/TimerOutputs.jl: Formatted output of timed sections in...](https://github.com/KristofferC/TimerOutputs.jl)**
>
> Formatted output of timed sections in Julia. Contribute to KristofferC/TimerOutputs.jl development by creating an account on GitHub.

useful.
