[julia-users] Re: Why does map allocate so much more than a list comprehension?
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)
[julia-users] Re: Why does map allocate so much more than a list comprehension?
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 (848 bytes allocated) See http://julia.readthedocs.org/en/latest/manual/performance-tips/#avoid-global-variables in the manual.
[julia-users] Re: Why does map allocate so much more than a list comprehension?
On Thursday, September 18, 2014 2:31:14 PM UTC-5, Johan Sigfrids wrote: So I was looking at allocations in some code and I noticed I sped things up significantly by changing map to a list comprehension. Doing some microbenchmarking I noticed that map allocates far more memory than a list comprehension. Shouldn't they essentially be doing the same thing? map() is a generic function call, and doesn't specialize on parameter values. The list comprehension is special syntax. The following should be instructive: code_llvm(f1, (Array{Float64, 1},)) vs. code_llvm(f2, (Array{Float64, 1},)) Making map() fast is one of the nearish-term goals. The latest discussion on map-related topics starts here: https://github.com/JuliaLang/julia/issues/8389#issuecomment-55930448