There is a sumabs function in Base for this reason. We'd like to eventually be able to do stream fusion to make the vectorized version as efficient as the manually fused version, but for now there's a performance gap. Note that the vectorized version is the same speed you would get in other languages where you express this in vectorized form – it's just that you can get much faster with manual loop fusion.
On Thu, Aug 21, 2014 at 11:03 PM, John Myles White <johnmyleswh...@gmail.com > wrote: > Please read http://julialang.org/blog/2013/09/fast-numeric/ > > — John > > On Aug 21, 2014, at 8:02 PM, K Leo <cnbiz...@gmail.com> wrote: > > > A is a 1-dimensional array. I used to compute sum(abs(A)). But when I > changed to the following, the speed increased nearly 10 fold. Why is that? > > > > sumA=0 > > for i=1:length(A) > > sumA = sumA + abs(A[i]) > > end > >