Preallocating the result of getindex(...)

I can’t reproduce the original timing results. For me, the copy! version is slightly faster. I’m also getting fewer allocations than you in both cases. Are you on 0.6?

BTW, replacing copy!(Atmp, view(A, :, inds)) with Atmp .= view(A, :, inds) is slightly faster for me; it appears that the generic AbstractArray version of copy! isn’t fully inlined for matrices (it is for vectors).

Edit: it’s not just the inlining; it appears the code for the broadcast version is also just faster than the code for copy!.

1 Like