# OpenBLAS: Julia slower than R

**URL:** <https://discourse.julialang.org/t/openblas-julia-slower-than-r/21594>\
**Category:** Performance\
**Tags:** linearalgebra\
**Created:** [March 7, 2019, 7:18pm UTC](https://discourse.julialang.org/t/openblas-julia-slower-than-r/21594 "2019-03-07T19:18:17Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 7, 2019, 7:30pm UTC](https://discourse.julialang.org/t/openblas-julia-slower-than-r/21594/2 "2019-03-07T19:30:43Z")

</div>

> [@pedro.rafae](#):
>
> Dear, I am not a programmer for **Julia** and so most likely my doubt is due to the little knowledge I have of **Julia**.

You are timing the inversion of a 5000x5000 matrix — this O(n³) operation completely dominates every other operation — so the benchmark has nothing to do with language. It depends entirely on which linear-algebra library is linked and how many threads it is using.

> [@pedro.rafae](#):
>
> the `solve` function of **R** is implemented in **C** or **Fortran** and the `inv` is implemented in **Julia**.

That’s not correct. For double-precision calculations (`Float64`), Julia, R, Numpy, Matlab, etcetera all do matrix inversion with [LAPACK](https://en.wikipedia.org/wiki/LAPACK), but there are different optimized versions of LAPACK (or the underlying BLAS library) that can be linked by all of these. Sometimes people link [OpenBLAS](https://www.openblas.net/), sometimes they link [MKL](https://en.wikipedia.org/wiki/Math_Kernel_Library), or sometimes another library — both Julia [and R](https://www.r-bloggers.com/faster-r-through-better-blas/) can be linked with various BLAS libraries with different tradeoffs. In your benchmark, you are mostly timing which BLAS library was linked. Also, different libraries use different numbers of threads by default.

In Julia, you can find out the BLAS library you are using via:

```julia
using LinearAlgebra
BLAS.vendor()

```

I’m not sure what the easiest way to determine this is for R.

Basically, if you are doing computations that are dominated by dense-matrix operations like solving Ax=b or Ax=λx, it doesn’t really matter what language you are using because every language uses LAPACK and can be configured link to the same BLAS libraries. But if you do enough computational work, eventually you are going to run into a problem where you have to write your own “inner loops” (performance-critical code), and that’s where language choice matters. To do a useful cross-language benchmark, you need to be timing inner-loop code, not calls to external libraries.

---

_[View the full topic](https://discourse.julialang.org/t/openblas-julia-slower-than-r/21594)._
