# Overhead of view / reshape / transpose in linear algebra

**URL:** https://discourse.julialang.org/t/overhead-of-view-reshape-transpose-in-linear-algebra/110761
**Category:** Performance
**Tags:** linearalgebra
**Created:** [February 26, 2024, 8:38am UTC](https://discourse.julialang.org/t/overhead-of-view-reshape-transpose-in-linear-algebra/110761 "2024-02-26T08:38:24Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![jsjie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jsjie/32/22477_2.png) [@jsjie](https://discourse.julialang.org/u/jsjie)
#### Post date: [June 13, 2024, 6:43am UTC](https://discourse.julialang.org/t/overhead-of-view-reshape-transpose-in-linear-algebra/110761/4 "2024-06-13T06:43:09Z")

</div>

Maybe I’ve found another case, and since it’s so highly related to this topic, I just unaccept your answer and put it here. I’m using Julia 1.10.2.

```julia
julia> using LinearAlgebra
julia> using BenchmarkTools
julia> buffer = zeros(ComplexF64, 10000);
julia> psi = reshape(view(buffer, 1:5000), 50, 100);
julia> hpsi = reshape(view(buffer, 5001:10000), 50, 100);
julia> function _f1!(psi, hpsi)
           view(psi, :, 1) .+= view(hpsi, :, 1)
       end
_f1! (generic function with 1 method)
julia> function _f2!(psi, hpsi)
           BLAS.axpy!(50, complex(1.0, 0.0), pointer(hpsi, 1), 1, pointer(psi, 1), 1)
       end
_f2! (generic function with 1 method)
julia> @btime _f1!(psi, hpsi);
  4.547 μs (3 allocations: 78.27 KiB)
julia> @btime _f2!(psi, hpsi);
  45.122 ns (1 allocation: 16 bytes)
julia> @btime _f1!($psi, $hpsi);
  4.585 μs (2 allocations: 78.17 KiB)
julia> @btime _f2!($psi, $hpsi);
  29.575 ns (0 allocations: 0 bytes)

```

I think they are doing the same thing and the last two measurements should have no artifacts?

---

_[View the full topic](https://discourse.julialang.org/t/overhead-of-view-reshape-transpose-in-linear-algebra/110761)._
