# Possible inefficiency in randn!

**URL:** <https://discourse.julialang.org/t/possible-inefficiency-in-randn/22732>\
**Category:** Performance\
**Tags:** benchmark\
**Created:** [April 4, 2019, 4:19am UTC](https://discourse.julialang.org/t/possible-inefficiency-in-randn/22732 "2019-04-04T04:19:25Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![antoine-levitt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antoine-levitt/32/4008_2.png) [@antoine-levitt](https://discourse.julialang.org/u/antoine-levitt)\
**Post date:** [April 4, 2019, 8:02am UTC](https://discourse.julialang.org/t/possible-inefficiency-in-randn/22732/5 "2019-04-04T08:02:29Z")

</div>

I was confused in the previous post, sorry. That has nothing to do with `simd`:

```julia
using Random
broadcast_randn(x) = (x .= randn.())
inplace_randn(x) = randn!(x)

function myrandn!(x)
    @inbounds @simd for i in eachindex(x)
        x[i] = randn()
    end
    x
end

function myrandn_nosimd!(x)
    @inbounds for i in eachindex(x)
        x[i] = randn()
    end
    x
end

x = zeros(10_000)
@btime broadcast_randn($x);
@btime inplace_randn($x);
@btime myrandn!($x);
@btime myrandn_nosimd!($x);

```

is only slow in `inplace_randn`. The real difference in the two cases is that `randn` isn’t inlined in `randn!`. This is despite `randn` being marked as `@inline`, so it looks like the inlining heuristics are being too conservative here.

---

_[View the full topic](https://discourse.julialang.org/t/possible-inefficiency-in-randn/22732)._
