Benchmarking Julia vs NumPy

Hello, I decided to make couple of benchmarks against NumPy out of curiosity.
Since I don’t know Julia it would be nice if someone could take a second look because based on what I measured it doesn’t look like Julia is faster especially in matrix multiplication and norm.

The results are here

Julia 1.4.0 benchmark code is here:

Thank you!

Numpy benchmark code is here:

It matters a lot how these benchmarks are executed. Numpy uses a blas library with a certain number of threads, executing for instance matrix-matrix multiplication in parallel. If one does not start Julia with multiple threads, it is hobbled.

There are several threads on this forum where you will find more information. Search for numpy and benchmark.

1 Like

Thank you.
Both were using multiple threads.
However, NumPy used MKL as backend (Linux conda).
Julia used OpenBLAS (Linux).

1 Like

You are using non-constant globals.

1 Like

Also, test2() is doing matrix multiplication.

And anyway, as you seem to know, all the work is done by the library. If you run both with the same library, then you will be benchmarking your benchmarking technique…

FWIW, on my computer the difference seems much less than 10x for test4, is it really this different on your computer, or was there a copy-paste error?

julia> @btime $float_matrixA * $float_matrixC; # test4, MKL — 0.001_856 in your table
  946.013 μs (2 allocations: 1.91 MiB)

julia> @btime $float_matrixA * $float_matrixC; # test4, OpenBLAS — 0.019_880 in your table
  1.191 ms (2 allocations: 1.91 MiB)
1 Like

I see, thank you. Just retested with all globals prepended with const. The results improved a but not drastically (still slower than NumPy).

As @improbable22 said, you’re comparing different operations. This line: is labeled as “element-wise multiplication”, but you’re actually doing matrix multiplication and then comparing it with element-wise multiplication in numpy.

1 Like

Indeed! Corrected.
Sorry, didn’t understand your last sentence. I thought just @btime is enough for such simple tests.

If you want to use MKL with Julia, the easiest way is to install MKL.jl.