I want to measure the total amount of time nedded to perform a complete loop. I tried
@time for i in 1:10000
and it returned
.988083 seconds (57.58 M allocations: 39.867 GiB, 0.14% gc time) when the code ran about 15 minutes to complete the loop and not 0.988083 seconds as indicated. How can I measure time correctly?
Tell us what’s in the
...? Normally what you did should work fine.
It should all be fine unless you have
@asyncs or threads or whatever. It’s easy to convince yourself that this should work fine:
julia> @time for i = 1:3
3.006142 seconds (15 allocations: 432 bytes)
So there has to be something else going on.
Ah thanks @tim.holy! Will check my code then
@time often seems to miss compilation time, at least in generated functions:
julia> @generated function slow_to_compile(x)
slow_to_compile (generic function with 1 method)
julia> t0 = time(); @time for i ∈ 1:3
end; time() - t0
6.009163 seconds (15 allocations: 432 bytes)
Julia Version 1.6.0-DEV.355
Commit 955beb6a91* (2020-07-02 10:28 UTC)
This is a big of a tangent, but you shouldn’t be doing heavy computations in a globally scoped
for loop as this will be quite bad for performance and memory usage. Consider using a
let block or a function (and avoid global variables).
Just out of curiosity, are you using Juno? I saw it sometimes in Juno, that output of @time is being partially “eaten” in console, I guess it’s some weird bug.
Yes I’m using Juno, indeed!