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

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

> #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

@time begin

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?

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

julia> using Dates

julia> t1 = now()

julia> t2 = now()

julia> t2 - t1
5621 milliseconds
1 Like

Thank you. I also found an alternative way using:

a = time()
b = time()
println(b -a)

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> t1 = now()

julia> t2 =now() + Hour(1)

julia> t2 - t1
3609039 milliseconds

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

That’s good to know. Thank you!

1 Like