On Monday, September 22, 2014 4:46:31 PM UTC-7, Carlos P wrote:
>
> and inlining the function seems to allocate even much more memory (almost
> 25 times more)...
> Any reason why?
>
> data = rand(10^6)
> f1(data) = [sin(i) for i in data]
>
> julia> @time f1(data);
> elapsed time: 0.023104734 seconds (8000128 bytes allocated)
>
> julia> @time [sin(i) for i in data];
> elapsed time: 1.056091612 seconds (199975552 bytes allocated, 23.74% gc
> time)
>
This is the general "global scope" issue that comes up in the REPL. If you
make "data" const, the difference goes away.
julia> const data = rand(10^6)
julia> @time [sin(i) for i in data]
elapsed time: 0.014063883 seconds (8000048 bytes allocated)
See
http://julia.readthedocs.org/en/latest/manual/performance-tips/#avoid-global-variables
in the manual.