# View and Slices: comparison of speed

**URL:** https://discourse.julialang.org/t/view-and-slices-comparison-of-speed/8647
**Category:** Performance
**Tags:** question
**Created:** [January 27, 2018, 10:59pm UTC](https://discourse.julialang.org/t/view-and-slices-comparison-of-speed/8647 "2018-01-27T22:59:09Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [January 27, 2018, 11:44pm UTC](https://discourse.julialang.org/t/view-and-slices-comparison-of-speed/8647/5 "2018-01-27T23:44:00Z")

</div>

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

```julia
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)

```

---

_[View the full topic](https://discourse.julialang.org/t/view-and-slices-comparison-of-speed/8647)._
