Hi guys,

I tried example from 0.4 Julia manual. My edited code:

A = rand(1_000_000);
const B = rand(1_000_000);

#non const
[ 0.25*A[i-1] + 0.5*A[i] + 0.25*A[i+1] for i=2:length(A)-1 ]

#const
[ 0.25*B[i-1] + 0.5*B[i] + 0.25*B[i+1] for i=2:length(B)-1 ]

#my mistake
[ 0.25*B[i-1] + 0.5*B[i] + 0.25*B[i+1] for i=2:length(A)-1 ]

#for comparing
[ 0.25*b[i-1] + 0.5*b[i] + 0.25*b[i+1] for i=2:1_000_000-1 ]

I have some questions:

1. Why has Julia problem with non constant Float64? (@time macro returned 
1.443342 
seconds (16.00 M allocations: 297.499 MB, 49.01% gc time)-1st case vs. 0.007271 
seconds (2 allocations: 7.629 MB)-2nd case)
2. Why Julia slow down after my mistake in 3rd case (length(A) with 
computation of B vector, @time macro returned 1.583760 seconds (16.00 M 
allocations: 297.499 MB, 54.18% gc time)-3rd case vs. 0.006969 seconds (2 
allocations: 7.629 MB)-4th case)
Thanks for your help :)

Reply via email to