Gaussian Elimination Function that is Fast

I was testing this package from this repository, it is faster than A \ b

I do not know any other competitor for calculating Gaussian Elimination that can be measured with @time. If anyone knows, I would like to know and do benchmark test on all of them.

This is from Julia REPL and JupyterNotebook:

A couple of suggestions: do not test with @time in the global scope. Use BenchmarkTools to test performance.
For instance

julia> b = rand(3)
3-element Vector{Float64}:

julia> A = rand(3, 3)
3×3 Matrix{Float64}:
 2.81443e-01  1.72279e-01  4.03091e-01
 2.49288e-01  2.35197e-01  2.02405e-01
 2.82910e-01  8.54934e-01  9.42708e-01

julia> using BenchmarkTools

julia> @btime $A \ $b
  563.934 ns (3 allocations: 288 bytes)
3-element Vector{Float64}:


Great suggestion, what is the different with this BenchmarkTools?

The result is the other way around now.

Capture d’écran_2022-07-24_21-14-14

You should take a look at the BenchmarkTools documentation, where it is explained why you should not use global variables when benchmarking. Note the dollar signs in @PetrKryslUCSD’s code. Also, it is nicer to provide example code and outputs in code blocks rather than using screen images. That way other people can copy and paste your examples.

1 Like

A couple more packages for you to look at: MKL and RecursiveFactorization.

1 Like

LAPACK, OpenBLAS, MKL etc are all optimized for large matrices. For a tiny matrix like 3x3 they introduce a lot of overhead and a simple loop will often be faster.

But if you have lots of tiny 3x3 systems it will be faster still to use StaticArrays, which can unroll and inline everything.


I try BenchmarkTools on finding a solution of a linear system and compare the time for two different methods in Julia:

A = [1 2 3;
     2 5 3;
     1 0 8]

b = [5; 3; 17]
using BenchmarkTools

@btime $A \ $b
@btime inv(A)*b

Capture d’écran_2022-07-25_19-14-16