I measured the speed for mapping a function of several variables on slices and views of arrays.
The speed of slicing seems to be higher than views!
And using the macro form, @view, increases the speed compared to the explicit functional form, view(...) !
The size of allocations are the same for all three forms, but the number of allocations is considerably lower for the slicing.
That’s because you’re not really allocating new slices in the first place. Both xs and ys look to be ranges – and slicing a range produces another range. Ranges are compact representations of vectors with evenly increasing values. Try it with xs=collect(1:N0) instead.
Even still, the speed of views isn’t always a win – that’s one reason why we decided not to make it the default.
Allocating a new range is about the same cost and size as allocating a view into a range. Try it with vectors instead of ranges and you’ll see a difference in memory allocated but the allocation count may be similar since we still cannot always eliminate allocating view objects (but a lot of work has been done on that).