If you need fast operations for small matrices, I highly recommend it FixedSizeArrays. For example:
using FixedSizeArrays
function foo(A, b, n)
s = 0.0
for i = 1:n
s += sum(A*b)
end
s
end
function foo2(A, b, n)
c = A*b
s = 0.0
for i = 1:n
A_mul_B!(c, A, b)
s += sum(c)
end
s
end
A = rand(3,3)
b = rand(3)
Af = Mat(A)
bf = Vec(b)
foo(A, b, 1)
foo2(A, b, 1)
foo(Af, bf, 1)
@time 1
@time foo(A, b, 10^6)
@time foo2(A, b, 10^6)
@time foo(Af, bf, 10^6)
Results:
julia> include("/tmp/foo.jl")
0.000005 seconds (148 allocations: 10.151 KB)
0.325433 seconds (2.00 M allocations: 106.812 MB, 9.07% gc time)
0.144793 seconds (8 allocations: 304 bytes)
0.012683 seconds (6 allocations: 192 bytes)
foo2 , FixedSizeArrays.