On Friday, 12 September 2014 02:24:15 UTC+1, [email protected] wrote:

> Wouldn't it be enough to put it in a local scope (let block or in a 
> function?).
>
> For more information, you can ask or look at the Performance tips part of 
> the manual.
>
I'd be interested in. Here is another code block:

a1 = rand(10, 10, 100, 100)
b1 = rand(10, 100, 100)
c1 = rand(10, 100, 100)
const a2 = rand(10,10,100,100)
const b2 = rand(10,100,100)
const c2 = rand(10,100,100)
@time(begin
    for n = 1:10
        d1 = Float64[ a1[a,b,i,j] .* b1[a,i,j] .* c1[b,i,j] for a = 1:10, b 
= 1:10, i=1:100,j=1:100 ]
    end
end)
@time(begin
    for n = 1:10
        d2 = [ a2[a,b,i,j] .* b2[a,i,j] .* c2[b,i,j] for a = 1:10, b = 
1:10, i=1:100,j=1:100 ]
    end
end)


OUTPUT:

elapsed time: 4.554876933 seconds (1039919360 bytes allocated, 25.73% gc time)
elapsed time: 0.147784029 seconds (80001120 bytes allocated, 54.91% gc time)

This is a factor-30 slow-down. I think comprehensions are wonderful to 
read, but this makes them useless, unless there is a reasonably elegant fix.

Reply via email to