Reputation: 421
temp=0
@elapsed for k in 1:1000
global temp+=k
end
will return elapsed time. But how can you save this into a variable?
temp=0
time=@elapsed for k in 1:1000
global temp+=k
end
I think this worked in previous versions of Julia? But for 1.0.0 I get
cannot assign variable libc.time from module Main
Also it does time the whole for loop correct? I'm really saddened by tic
and toc
being unusable in 1.0.0, I think the logic was simpler there.
Upvotes: 1
Views: 3576
Reputation: 20950
Well, it quite clearly tells you that time
is an existing variable (namely, a function) in Main
:
julia> time
time (generic function with 2 methods)
So, just name your result differently:
julia> ime=@elapsed for k in 1:1000
global temp+=k
end
6.6707e-5
julia> ime
6.6707e-5
Upvotes: 2