# How to measure execution time of entire jupyter notebook comprising of different cells in JULIA?

**URL:** https://discourse.julialang.org/t/how-to-measure-execution-time-of-entire-jupyter-notebook-comprising-of-different-cells-in-julia/68517
**Category:** General Usage
**Tags:** question, package
**Created:** [September 21, 2021, 9:48am UTC](https://discourse.julialang.org/t/how-to-measure-execution-time-of-entire-jupyter-notebook-comprising-of-different-cells-in-julia/68517 "2021-09-21T09:48:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![H\_Shrestha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/h_shrestha/32/29375_2.png) [@H\_Shrestha](https://discourse.julialang.org/u/H_Shrestha)
#### Post date: [September 21, 2021, 9:48am UTC](https://discourse.julialang.org/t/how-to-measure-execution-time-of-entire-jupyter-notebook-comprising-of-different-cells-in-julia/68517/1 "2021-09-21T09:48:00Z")

</div>

have a script written in JULIA language in Jupyter notebook. The script is divided into different cells. I’d like to calculate the execution time of not only a single line or cell, but the entire script comprising all the cells. In Python, I could do it using

```julia
> #In the beginning of script
> import time
> a = time.time()
> ...
> ...
> #At the end of script
> b= time.time()
> b - a

```

I’d like to have something similar to calculate the execution time of the entire script in JULIA. I tried using

```julia
@time begin
...
end

```

However, this works with a single line or cell only and does not seem to work when I put the statements in the beginning and end of the script if they are in different cells. How can I get the execution time of the entire script comprising all cells?

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [September 21, 2021, 9:58am UTC](https://discourse.julialang.org/t/how-to-measure-execution-time-of-entire-jupyter-notebook-comprising-of-different-cells-in-julia/68517/2 "2021-09-21T09:58:04Z")

</div>

Just do the same thing you’d do in Python:

```julia
julia> using Dates

julia> t1 = now()
2021-09-21T10:57:35.616

julia> t2 = now()
2021-09-21T10:57:41.237

julia> t2 - t1
5621 milliseconds

```

---

<div class="post-metadata">

### Author: ![H\_Shrestha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/h_shrestha/32/29375_2.png) [@H\_Shrestha](https://discourse.julialang.org/u/H_Shrestha)
#### Post date: [September 21, 2021, 10:11am UTC](https://discourse.julialang.org/t/how-to-measure-execution-time-of-entire-jupyter-notebook-comprising-of-different-cells-in-julia/68517/3 "2021-09-21T10:11:32Z")

</div>

Thank you. I also found an alternative way using:

```julia
a = time()
#...
b = time()
println(b -a)

```

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [September 21, 2021, 10:17am UTC](https://discourse.julialang.org/t/how-to-measure-execution-time-of-entire-jupyter-notebook-comprising-of-different-cells-in-julia/68517/4 "2021-09-21T10:17:20Z")

</div>

That works but you lose the nice formatting - given that `Dates` is a standard library there’s pretty much no overhead to using it, and it gives you nice formatting like

```julia
julia> t1 = now()
2021-09-21T11:16:11.382

julia> t2 =now() + Hour(1)
2021-09-21T12:16:20.421

julia> t2 - t1
3609039 milliseconds

julia> canonicalize(t2 - t1)
1 hour, 9 seconds, 39 milliseconds

```

---

<div class="post-metadata">

### Author: ![H\_Shrestha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/h_shrestha/32/29375_2.png) [@H\_Shrestha](https://discourse.julialang.org/u/H_Shrestha)
#### Post date: [September 21, 2021, 10:26am UTC](https://discourse.julialang.org/t/how-to-measure-execution-time-of-entire-jupyter-notebook-comprising-of-different-cells-in-julia/68517/5 "2021-09-21T10:26:54Z")

</div>

That’s good to know. Thank you!
