# Speeding up the multiplying, adding, subtracting of 3D matrices

**URL:** https://discourse.julialang.org/t/speeding-up-the-multiplying-adding-subtracting-of-3d-matrices/100488
**Category:** Numerics
**Tags:** question
**Created:** [June 17, 2023, 1:13pm UTC](https://discourse.julialang.org/t/speeding-up-the-multiplying-adding-subtracting-of-3d-matrices/100488 "2023-06-17T13:13:37Z")
**Posts on this page:** 1
**Showing post:** 15

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [June 20, 2023, 7:20pm UTC](https://discourse.julialang.org/t/speeding-up-the-multiplying-adding-subtracting-of-3d-matrices/100488/15 "2023-06-20T19:20:59Z")

</div>

This is what I mean:

```julia
julia> C, A, B = (rand(91,91,91) for _ in 1:3); range = 1:30;

julia> function f!(C,A,B,r)
           C[r,r,r] .= A[r,r,r] .* B[r,r,r]
       end
f! (generic function with 1 method)

julia> @btime f!($C, $A, $B, $range);
  67.778 μs (4 allocations: 422.00 KiB)

julia> @views function f!(C,A,B,r)
           C[r,r,r] .= A[r,r,r] .* B[r,r,r]
       end
f! (generic function with 1 method)

julia> @btime f!($C, $A, $B, $range);
  21.476 μs (0 allocations: 0 bytes)

```

and, please, follow the guidelines here: [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

---

_[View the full topic](https://discourse.julialang.org/t/speeding-up-the-multiplying-adding-subtracting-of-3d-matrices/100488)._
