I’m using SMatrix from StaticArrays.jl for calculation of coordinate system transformation. In the hotspot, I’m running following (simplified) code:
using StaticArrays, BenchmarkTools
a = rand(3)
b = rand(3)
c = rand(3)
d = rand(3)
m = hcat((a-d),(b-d),(c-d))
sm = SMatrix{3,3}(hcat((a-d),(b-d),(c-d))...)
m==sm
f1(a,b,c,d) = SMatrix{3,3}(hcat((a-d),(b-d),(c-d))...)
f2(a,b,c,d) = SMatrix{3,3}((a-d)...,(b-d)...,(c-d)...)
@inline function smatrix33(a,b,c)
@inbounds A = SMatrix{3,3}(a[1], a[2], a[3], b[1], b[2], b[3], c[1], c[2], c[3])
A
end
f3(a,b,c,d) = smatrix33((a-d),(b-d),(c-d))
The result medians are for f1, f2 and f3 1.2 us, 780 ns and 174 ns.
Is there a better way to fill an SMatrix by column / row vectors, or is it necessary to write a helper function to get the full speed?