View and Slices: comparison of speed

That’s just an artifact of doing your timing at global scope:

julia> fslices(xs, ys) = map(secant, xs[1:end-1], xs[2:end], ys[1:end-1], ys[2:end])

julia> fviews(xs, ys) = map(secant, @view(xs[1:end-1]), @view(xs[2:end]), @view(ys[1:end-1]), @view(ys[2:end]) )

julia> fslices(xs, ys); @time fslices(xs, ys);
  0.024084 seconds (6 allocations: 7.630 MiB)

julia> fviews(xs, ys); @time fviews(xs, ys);
  0.029539 seconds (6 allocations: 7.630 MiB)

julia> xs′ = collect(xs);
       ys′ = collect(ys);

julia> fslices(xs′, ys′); @time fslices(xs′, ys′);
  0.030760 seconds (18 allocations: 38.148 MiB)

julia> fviews(xs′, ys′); @time fviews(xs′, ys′);
  0.027073 seconds (14 allocations: 7.630 MiB)
4 Likes