結論 サイズの小さい、かつ固定長の線形代数の計算はStaticArrays.jlを使おう 実験 公式ドキュメントのPerformance Tipsには、計算結果をPre-allocateする工夫として、次の例が掲載されています。 function xinc(x) return [x, x+1, x+2] end; function loopinc() y = 0 for i = 1:10^7 ret = xinc(i) y += ret[2] end return y end; function xinc!(ret::AbstractVector{T}, x::T) where T ret[1] = x ret[2] = x+1 ret[3] = x+2 nothing end; function loopinc_prealloc() ret = Vector{Int}(undef, 3)