Efficient repeated sampling of small vector

This has issues with global variables benchmarking, you avoid it with $-interpolation in the macro expression. And the function appears to not use its argument and uses a type-unstable global b, which I assume was a mistake. Is this what you intended?

a = zeros(10000)
@btime randn!($a) #
b = zeros(10)
foo(x) = for _ in 1:1000 randn!(x) end
@btime foo($b) #

Doesn’t seem to change the performance discrepancy much.

1 Like