# 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:** 119

<div class="post-metadata">

**Author:** ![Amin\_Yahyaabadi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amin_yahyaabadi/32/9826_2.png) [@Amin\_Yahyaabadi](https://discourse.julialang.org/u/Amin_Yahyaabadi)\
**Post date:** [October 13, 2019, 10:32pm UTC](https://discourse.julialang.org/t/benchmark-matlab-julia-for-matrix-operations/2000/119 "2019-10-13T22:32:38Z")

</div>

The way you call manual measuring is incorrect.

Internally, `timeit()` calls the function many times and measures the time took for the whole process, not every individual call!

Just run `open timeit`, to see the code:

```matlab
% timeit for Matlab:
for k = 1:num_outer_iterations
        tic(); % t1 = tic();...t = toc(t1) NOT used because not JIT-ed
	for p = 1:num_inner_iterations
	    output = f(); %#ok<NASGU>
	end
	runtimes(k) = toc();
end
t = median(runtimes) / num_inner_iterations;

```

I have another outer loop which calls timeit 4 times, and averages this median ([https://github.com/juliamatlab/Julia-Matlab-Benchmark/blob/6e6e015efcce883f47e2942d8b60ed69315b265f/MatlabBench.m#L45](https://github.com/juliamatlab/Julia-Matlab-Benchmark/blob/6e6e015efcce883f47e2942d8b60ed69315b265f/MatlabBench.m#L45))

The `timeit` [itself calls the function multiple times and returns the median,](https://www.mathworks.com/help/matlab/ref/timeit.html) then I calculate the average of different returns.

For example, inside timeit for matrix inversion, it runs 11\*100 iterations and median is returned, and my 4 iterations wrap that to calculate the average of every 1100 iterations’ median. If I make the number of iterations around it 50, it becomes like 55000 iterations! while I explicitly stated Julia’s sample number as 700 in the code.

In contrast to your code, which measures every call and then calculates the median!

> <https://github.com/RoyiAvital/MatlabJuliaMatrixOperationsBenchmark/blob/4dca9188f258538d28cb35d263cd0ea909ba11a6/MatlabMatrixBenchmark0001.m#L129>

If you are suspicious about two different branches on my repository, you can run it and make a pull request. Check my Windows system’s specifications:

> **[Dell Latitude 5590 Performance Results - UserBenchmark](https://www.userbenchmark.com/UserRun/20906483)**

The performance of my system’s CPU is very good.

It is not about openBLAS or Intel. It is just a simple parallel processing concept that `overhead for parallel processing should worth it!`.

---

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