m=0.0
@time for i=1:1000000
r= rand()-.05
m=max(m,abs(r))
end
allocates 32 MB of memory.
I do not have this problem when I write for loops over vector components, but how can I overwrite scalars in Julia?
Thanks a lot and looking forward to any possible tips or ideas.
-Mike
julia> function test() m=0.0 @time for i=1:1000000 r= rand()-.05 m=max(m,abs(r)) end; m endtest (generic function with 1 method)
julia> test()elapsed time: 0.004459659 seconds (0 bytes allocated)0.9499997082184952
julia> begin m=0.0 @time for i=1:1000000 r= rand()-.05 m=max(m,abs(r)) end; m endelapsed time: 0.040078291 seconds (32002568 bytes allocated)0.9499986056323748function foo(n)
m = 0.0
for i=1:n
r= rand()-.05
m=max(m,abs(r))
end
return m
end
@time foo(1000000)
elapsed time: 0.005688064 seconds (96 bytes allocated)julia --track-allocation=user yourscript.jl.