In MATLAB, there are a pair of functions tic
and toc
which can be used to start and stop a stopwatch timer.
An example taken from link:
tic
A = rand(12000, 4400);
B = rand(12000, 4400);
toc
C = A'.*B';
toc
I am aware that there is a macro @time
in Julia
that has similar functionality.
julia> @time [sin(cos(i)) for i in 1:100000];
elapsed time: 0.00721026 seconds (800048 bytes allocated)
Is there a set of similar functions in Julia?
The @time
macro works well for timing statements
that can be written in one or two lines.
For longer portions of code,
I would prefer to use tic-toc functions.
When I googled "julia stopwatch", I found one useful link and four unrelated links.
I don't know why I hadn't thought of just trying tic()
and toc()
.
tic()
and toc()
have been deprecated as of https://github.com/JuliaLang/julia/commit/1b023388f49e13e7a42a899c12602d0fd5d60b0a
You can use @elapsed
and @time
for longer chunks by wrapping them in an environment, like so:
t = @elapsed begin
...
end
There is also TickTock.jl, which has reimplemented tic()
and toc()
and tick()
and tock()
.
using TickTock
tick()
# Started timer at 2017-12-13T22:30:59.632
tock()
# 55.052638936 ms: 55 seconds, 52 milliseconds
From a search of the Julia documentation
tic()
Set a timer to be read by the next call to
toc()
ortoq()
. The macro call@time expr
can also be used to time evaluation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With