# Using @inbounds

**URL:** <https://discourse.julialang.org/t/using-inbounds/7499>\
**Category:** Performance\
**Created:** [December 4, 2017, 4:25pm UTC](https://discourse.julialang.org/t/using-inbounds/7499 "2017-12-04T16:25:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drjoke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drjoke/32/23562_2.png) [@drjoke](https://discourse.julialang.org/u/drjoke)\
**Post date:** [December 4, 2017, 4:25pm UTC](https://discourse.julialang.org/t/using-inbounds/7499/1 "2017-12-04T16:25:49Z")

</div>

```julia
@inbounds for j = 1:networks_hidden_layer_size[1]
            hidden_sums[j, 1, s, y, n] = 0
            for i = 1:networks_input_count[1]
                hidden_sums[j, 1, s, y, n] +=
                        networks_input_weights[i, j, n] *
                        observation_tensor_variables[i, s, y]
            end
end

```

Is the above use of @inbounds enough if I meant for @inbounds to cover everything inside the loop?? Or do I need to add @inbounds to every lines as in below.

```julia
@inbounds for j = 1:networks_hidden_layer_size[1]
            @inbounds hidden_sums[j, 1, s, y, n] = 0
            @inbounds for i = 1:networks_input_count[1]
                @inbounds hidden_sums[j, 1, s, y, n] +=
                        networks_input_weights[i, j, n] *
                        observation_tensor_variables[i, s, y]
            end
end

```

Does the same logic also follow for @simd ?

---

<div class="post-metadata">

**Author:** ![davidbp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidbp/32/463_2.png) [@davidbp](https://discourse.julialang.org/u/davidbp)\
**Post date:** [December 4, 2017, 4:34pm UTC](https://discourse.julialang.org/t/using-inbounds/7499/2 "2017-12-04T16:34:43Z")

</div>

Yes, everything inside the for will benefit.  
I am not sure about @simd. But @simd should be used only in very specific cases .
