# Benchmark MATLAB & Julia for Matrix Operations

**URL:** <https://discourse.julialang.org/t/benchmark-matlab-julia-for-matrix-operations/2000>\
**Category:** Performance\
**Created:** [February 9, 2017, 12:50pm UTC](https://discourse.julialang.org/t/benchmark-matlab-julia-for-matrix-operations/2000 "2017-02-09T12:50:37Z")\
**Posts on this page:** 1\
**Showing post:** 116

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 13, 2019, 8:38pm UTC](https://discourse.julialang.org/t/benchmark-matlab-julia-for-matrix-operations/2000/116 "2019-10-13T20:38:39Z")

</div>

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
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

```

---

_[View the full topic](https://discourse.julialang.org/t/benchmark-matlab-julia-for-matrix-operations/2000)._
