Const made the big difference,
But what is the problem with the inferred type?

Joaquim

> On 21 de dez de 2015, at 20:30, Milan Bouchet-Valat <[email protected]> wrote:
> 
> Le lundi 21 décembre 2015 à 14:04 -0800, Joaquim Masset Lacombe Dias
> Garcia a écrit :
>> Why is the order of these loops barely affects the time?
> Before doing this kind of comparison, you should ensure your code is
> written to run efficiently. For that, you need to do
> const N = 100
> 
> Else, the type of the variables isn't correctly inferred. Also, you
> need to call the functions once to exclude compilation time from the
> measurement.
> 
> After changing this (and fixing the name of the second argument for
> cba), I get the maximum time difference between abc and cba, the latter
> being 3x faster than the former (4x after adding @inbounds).
> 
> 
> Regards
> 
> 
>> N=100
>> x=rand(N,N,N)
>> y=rand(N,N,N)
>> 
>> function abc(x::Array{Float64,3},y::Array{Float64,3})
>>    for a=1:N
>>        for b=1:N
>>            for c=1:N
>>                y[a,b,c]=x[a,b,c]
>>            end
>>        end
>>    end
>> end
>> function acb(x::Array{Float64,3},y::Array{Float64,3})
>>    for a=1:N
>>        for c=1:N
>>            for b=1:N
>>                y[a,b,c]=x[a,b,c]
>>            end
>>        end
>>    end
>> end
>> function bac(x::Array{Float64,3},y::Array{Float64,3})
>>    for b=1:N
>>        for a=1:N
>>            for c=1:N
>>                y[a,b,c]=x[a,b,c]
>>            end
>>        end
>>    end
>> end
>> function bca(x::Array{Float64,3},y::Array{Float64,3})
>>    for b=1:N
>>        for c=1:N
>>            for a=1:N
>>                y[a,b,c]=x[a,b,c]
>>            end
>>        end
>>    end
>> end
>> function cab(x::Array{Float64,3},y::Array{Float64,3})
>>    for c=1:N
>>        for a=1:N
>>            for b=1:N
>>                y[a,b,c]=x[a,b,c]
>>            end
>>        end
>>    end
>> end
>> function cba(x::Array{Float64,3},xx::Array{Float64,3})
>>    for c=1:N
>>        for b=1:N
>>            for a=1:N
>>                y[a,b,c]=x[a,b,c]
>>            end
>>        end
>>    end
>> end
>> 
>> @time abc(x,y)
>> @time acb(x,y)
>> @time bac(x,y)
>> @time bca(x,y)
>> @time cab(x,y)
>> @time cba(x,y)

Reply via email to