What version of Julia are you using? You have almost 20x performance difference here, between f1
and f2
, that doesn’t seem right. I get only a 30% difference.
Also, when benchmarking, make sure to interpolate the variables in the benchmarking expressions:
@benchmark f1($A, $B)
@benchmark f2($A, $B)
Finally, if you are consistently using small matrices and vectors, where you know the sizes beforehand, you should definitely look at the StaticArray package, like @WschW suggests. You will probably get dramatic speedups that way, at least 10x I believe.