(Don’t benchmark in global scope. Use .=
for in-place assignment that fuses with operations like .*
.)
Note that for initializing only two components, the overhead even of creating a view, or calling broadcast
, or allocating a temporary array like [1,1]
will be very significant. For such a smll array in an inner loop, the fastest things are to write out your own loop or to use something like the StaticArrays package.