Benchmark MATLAB & Julia for Matrix Operations

you can potentially not using a compiled version of a function if you do @elapsed manually, for example you can do some heavy calculation in global scope and just wrap the whole block with @elapse, and even if you run multiple time of that block it’s still sub-optimal.

But I think in this matrix addition case you’re good:

julia> [MatrixAdditionRunTime(3000, randn(3000), randn(3000))[2] for _=1:10000] |> mean
5.7079562e-6

julia> @benchmark (scalarA .* mX) .+ (scalarB .* mY) setup=(scalarA=rand(); scalarB=rand(); mX=randn(3000); mY=randn(3000))
BenchmarkTools.Trial:
  memory estimate:  23.52 KiB
  allocs estimate:  2
  --------------
  minimum time:     1.000 μs (0.00% GC)
  median time:      2.390 μs (0.00% GC)
  mean time:        5.569 μs (26.64% GC)
  maximum time:     3.148 ms (99.79% GC)
  --------------
  samples:          10000
  evals/sample:     10
1 Like