Ok, I did that
function test(M,nbp)
Mr = zeros(nbp,nbp)
for k = 1:nbp
for kk = 1:nbp
Mr[k,kk] = M[k,kk]*M[k,kk];
end
end
return Mr
end
function main()
nbp = 2^12;
m = rand(nbp,nbp);
@time test(m,nbp)
end
main()
and yes it was much faster 0.627739 seconds (2 allocations: 128.000 MB,
1.34% gc time).
I'm not sure if I understand but I think I do.
Anyway thanks for the answer.
On Friday, July 1, 2016 at 4:26:01 PM UTC+2, John Myles White wrote:
>
> See the top of
> http://docs.julialang.org/en/release-0.4/manual/performance-tips/
>
> On Friday, July 1, 2016 at 7:16:10 AM UTC-7, baillot maxime wrote:
>>
>> Hello everyone,
>>
>> I am working on a Julia code which is a brutal copy of a Matlab code and
>> found out that the Julia code is slower.....
>>
>> So I did some naive benchmark and found strange results...
>>
>> I did look for solution on The Internets but... I found nothing usefull
>> that why I'm asking the question here.
>>
>> Maybe someone have an idea of why the Julia code is slower than MATLAB?
>> (because the official benchmark say that it should be quicker )
>>
>> PS: I know that it's a bit of a recurrent question....
>>
>> The codes are
>>
>> Julia code
>>
>> nbp = 2^12;
>>
>> m = rand(nbp,nbp);
>> a = 0.0;
>> Mr = zeros(nbp,nbp);
>>
>> tic()
>> for k = 1:nbp
>> for kk = 1:nbp
>>
>> Mr[k,kk] = m[k,kk]*m[k,kk];
>>
>> end
>> end
>> toc()
>>
>>
>> Elapsed time: 7.481011275 seconds
>>
>>
>> MATLAB code
>>
>> nbp = 2^12;
>>
>> m = rand(nbp,nbp);
>> a = 0.0;
>> Mr = zeros(nbp,nbp);
>>
>>
>> tic
>> for k = 1:nbp
>> for kk = 1:nbp
>>
>> Mr(k,kk) =m(k,kk)*m(k,kk);
>>
>> end
>> end
>> toc
>>
>>
>> Elapsed time is 0.618451 seconds.
>>
>>