Iterating over two vectors with vcat is faster than Iterators.flatten and CatViews?

And here’s a very barebones toy implementation of something similar (but of course less general):

struct MyCatView{N, T}
    arr::NTuple{N, Vector{T}}    
end
MyCatView(arrs::Vector{T}...) where {T} = MyCatView(arrs)
mysum(v::MyCatView) = sum(sum.(v.arr))

Then

julia> a, b = rand(1000), rand(1000);

julia> v = MyCatView(a, b);

julia> @btime mysum($v)
  192.796 ns (0 allocations: 0 bytes)

That’s three orders of magnitude faster(!) I think there must be something else going on.

1 Like