Creating an array

The top one is slower because it fills with zeros, the bottom one is faster because it only allocates memory.

julia> @btime Array1 = fill(0,100)
  30.242 ns (1 allocation: 896 bytes)
julia> @btime Array2 = Array{Int64}(undef,100)
  13.413 ns (1 allocation: 896 bytes)

If you don’t need the 0s, consider the latter.

4 Likes