Last active
September 6, 2017 01:12
-
-
Save chriselrod/c36f061df86ff862dc027474c4853248 to your computer and use it in GitHub Desktop.
LAPACK vs LinearAlgebra.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkTools, LinearAlgebra | |
#LinearAlgebra code at: https://github.com/andreasnoack/LinearAlgebra.jl | |
#Install LinearAlgebra via Pkg.clone("https://github.com/andreasnoack/LinearAlgebra.jl") | |
function gen_pos_def(p::Int) | |
X = randn( div(3p, 2), p) | |
S = X' * X | |
S, Hermitian(S, :L) | |
end | |
S20, H20 = gen_pos_def(20); | |
S35, H35 = gen_pos_def(33); | |
S40, H40 = gen_pos_def(40); | |
S100, H100 = gen_pos_def(100); | |
S133, H133 = gen_pos_def(133); | |
S150, H150 = gen_pos_def(150); | |
S300, H300 = gen_pos_def(300); | |
S1000, H1000 = gen_pos_def(1000); | |
#"Julia_eig" is actually identical to simply "eig" when "using LinearAlgebra" | |
#When not using LinearAlgebra, "eig" on a Symmetric or Hermitian matrix A will default to syevr!(copy(A)) | |
#Just want to make it clear what code both are running. | |
Julia_eig(A) = LinearAlgebra.EigenSelfAdjoint.eig!(copy(A)) | |
LAPACK_eig(A) = Base.LinAlg.LAPACK.syevr!('V', 'A', 'L', copy(A), 1.0, 1.0, 1, 1, eps()) | |
vals_j, vecs_j = Julia_eig(H40) | |
vals_L, vecs_L = LAPACK_eig(S40) | |
#Eigenvalues are approximately equal. | |
vals_j ≈ vals_L | |
#Eigenvectors are orthogonal. | |
vecs_j' * vecs_j ≈ eye(40) | |
vecs_L' * vecs_L ≈ eye(40) | |
@benchmark Julia_eig($H20) | |
@benchmark LAPACK_eig($S20) | |
@benchmark Julia_eig($H35) | |
@benchmark LAPACK_eig($S35) | |
@benchmark Julia_eig($H40) | |
@benchmark LAPACK_eig($S40) | |
@benchmark Julia_eig($H100) | |
@benchmark LAPACK_eig($S100) | |
@benchmark Julia_eig($H133) | |
@benchmark LAPACK_eig($S133) | |
@benchmark Julia_eig($H150) | |
@benchmark LAPACK_eig($S150) | |
@benchmark Julia_eig($H300) | |
@benchmark LAPACK_eig($S300) | |
@benchmark Julia_eig($H1000) | |
@benchmark LAPACK_eig($S1000) | |
############################################################################ | |
############################# Windows & Intel ############################## | |
############################################################################ | |
julia> versioninfo() | |
Julia Version 0.6.0 | |
Commit 903644385b* (2017-06-19 13:05 UTC) | |
Platform Info: | |
OS: Windows (x86_64-w64-mingw32) | |
CPU: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz | |
WORD_SIZE: 64 | |
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell) | |
LAPACK: libopenblas64_ | |
LIBM: libopenlibm | |
LLVM: libLLVM-3.9.1 (ORCJIT, haswell) | |
julia> vals_j, vecs_j = Julia_eig(H40) | |
([2.06457, 3.43887, 4.20197, 5.41251, 6.52628, 8.68195, 9.86435, 12.4965, 15.997 | |
7, 16.4481 . 99.4326, 99.9603, 109.002, 117.18, 120.139, 135.266, 147.287, 159 | |
.937, 163.705, 186.442], [0.175411 -0.0157983 . -0.0729909 0.345485; -0.122313 - | |
0.0702725 . 0.0162747 -0.0864244; . ; 0.267428 0.137832 . -0.0641975 0.171393; 0 | |
.0037438 -0.1076 . -0.0869933 -0.0728508]) | |
julia> vals_L, vecs_L = LAPACK_eig(S40) | |
([2.06457, 3.43887, 4.20197, 5.41251, 6.52628, 8.68195, 9.86435, 12.4965, 15.997 | |
7, 16.4481 . 99.4326, 99.9603, 109.002, 117.18, 120.139, 135.266, 147.287, 159 | |
.937, 163.705, 186.442], [0.175411 -0.0157983 . 0.0729909 -0.345485; -0.122313 - | |
0.0702725 . -0.0162747 0.0864244; . ; 0.267428 0.137832 . 0.0641975 -0.171393; 0 | |
.0037438 -0.1076 . 0.0869933 0.0728508]) | |
julia> #Eigenvalues are approximately equal. | |
julia> vals_j ≈ vals_L | |
true | |
julia> #Eigenvectors are orthogonal. | |
julia> vecs_j' * vecs_j ≈ eye(40) | |
true | |
julia> vecs_L' * vecs_L ≈ eye(40) | |
true | |
julia> @benchmark Julia_eig($H20) | |
BenchmarkTools.Trial: | |
memory estimate: 11.56 KiB | |
allocs estimate: 24 | |
-------------- | |
minimum time: 35.067 µs (0.00% GC) | |
median time: 35.923 µs (0.00% GC) | |
mean time: 38.622 µs (2.49% GC) | |
maximum time: 2.641 ms (97.42% GC) | |
-------------- | |
samples: 10000 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S20) | |
BenchmarkTools.Trial: | |
memory estimate: 18.03 KiB | |
allocs estimate: 15 | |
-------------- | |
minimum time: 157.375 µs (0.00% GC) | |
median time: 174.195 µs (0.00% GC) | |
mean time: 180.103 µs (1.01% GC) | |
maximum time: 2.608 ms (88.99% GC) | |
-------------- | |
samples: 10000 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H35) | |
BenchmarkTools.Trial: | |
memory estimate: 32.00 KiB | |
allocs estimate: 24 | |
-------------- | |
minimum time: 140.554 µs (0.00% GC) | |
median time: 145.686 µs (0.00% GC) | |
mean time: 151.807 µs (2.10% GC) | |
maximum time: 2.576 ms (91.45% GC) | |
-------------- | |
samples: 10000 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S35) | |
BenchmarkTools.Trial: | |
memory estimate: 43.05 KiB | |
allocs estimate: 15 | |
-------------- | |
minimum time: 450.457 µs (0.00% GC) | |
median time: 469.273 µs (0.00% GC) | |
mean time: 479.217 µs (0.89% GC) | |
maximum time: 2.953 ms (76.93% GC) | |
-------------- | |
samples: 10000 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H40) | |
BenchmarkTools.Trial: | |
memory estimate: 40.91 KiB | |
allocs estimate: 24 | |
-------------- | |
minimum time: 191.302 µs (0.00% GC) | |
median time: 197.289 µs (0.00% GC) | |
mean time: 204.647 µs (1.85% GC) | |
maximum time: 2.536 ms (90.58% GC) | |
-------------- | |
samples: 10000 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S40) | |
BenchmarkTools.Trial: | |
memory estimate: 53.45 KiB | |
allocs estimate: 15 | |
-------------- | |
minimum time: 560.221 µs (0.00% GC) | |
median time: 583.313 µs (0.00% GC) | |
mean time: 594.813 µs (0.85% GC) | |
maximum time: 3.257 ms (81.24% GC) | |
-------------- | |
samples: 8383 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H100) | |
BenchmarkTools.Trial: | |
memory estimate: 240.27 KiB | |
allocs estimate: 27 | |
-------------- | |
minimum time: 2.275 ms (0.00% GC) | |
median time: 2.316 ms (0.00% GC) | |
mean time: 2.367 ms (1.04% GC) | |
maximum time: 5.070 ms (52.26% GC) | |
-------------- | |
samples: 2111 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S100) | |
BenchmarkTools.Trial: | |
memory estimate: 272.25 KiB | |
allocs estimate: 19 | |
-------------- | |
minimum time: 2.939 ms (0.00% GC) | |
median time: 3.049 ms (0.00% GC) | |
mean time: 3.100 ms (0.82% GC) | |
maximum time: 7.278 ms (0.00% GC) | |
-------------- | |
samples: 1605 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H133) | |
BenchmarkTools.Trial: | |
memory estimate: 422.23 KiB | |
allocs estimate: 27 | |
-------------- | |
minimum time: 5.075 ms (0.00% GC) | |
median time: 5.169 ms (0.00% GC) | |
mean time: 5.244 ms (0.70% GC) | |
maximum time: 7.835 ms (25.84% GC) | |
-------------- | |
samples: 953 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S133) | |
BenchmarkTools.Trial: | |
memory estimate: 464.77 KiB | |
allocs estimate: 19 | |
-------------- | |
minimum time: 6.019 ms (0.00% GC) | |
median time: 6.160 ms (0.00% GC) | |
mean time: 6.232 ms (0.58% GC) | |
maximum time: 9.568 ms (18.64% GC) | |
-------------- | |
samples: 800 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H150) | |
BenchmarkTools.Trial: | |
memory estimate: 536.05 KiB | |
allocs estimate: 27 | |
-------------- | |
minimum time: 7.029 ms (0.00% GC) | |
median time: 7.273 ms (0.00% GC) | |
mean time: 7.373 ms (0.67% GC) | |
maximum time: 10.220 ms (20.95% GC) | |
-------------- | |
samples: 678 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S150) | |
BenchmarkTools.Trial: | |
memory estimate: 583.77 KiB | |
allocs estimate: 19 | |
-------------- | |
minimum time: 5.118 ms (0.00% GC) | |
median time: 5.526 ms (0.00% GC) | |
mean time: 5.640 ms (0.86% GC) | |
maximum time: 9.927 ms (0.00% GC) | |
-------------- | |
samples: 887 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H300) | |
BenchmarkTools.Trial: | |
memory estimate: 2.08 MiB | |
allocs estimate: 27 | |
-------------- | |
minimum time: 52.009 ms (0.00% GC) | |
median time: 53.261 ms (0.00% GC) | |
mean time: 53.488 ms (0.35% GC) | |
maximum time: 56.266 ms (3.95% GC) | |
-------------- | |
samples: 94 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S300) | |
BenchmarkTools.Trial: | |
memory estimate: 2.17 MiB | |
allocs estimate: 20 | |
-------------- | |
minimum time: 16.236 ms (0.00% GC) | |
median time: 17.151 ms (0.00% GC) | |
mean time: 17.474 ms (1.09% GC) | |
maximum time: 27.921 ms (0.00% GC) | |
-------------- | |
samples: 286 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H1000) | |
BenchmarkTools.Trial: | |
memory estimate: 22.94 MiB | |
allocs estimate: 27 | |
-------------- | |
minimum time: 1.848 s (0.52% GC) | |
median time: 1.884 s (0.51% GC) | |
mean time: 1.882 s (1.16% GC) | |
maximum time: 1.915 s (2.88% GC) | |
-------------- | |
samples: 3 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S1000) | |
BenchmarkTools.Trial: | |
memory estimate: 23.25 MiB | |
allocs estimate: 20 | |
-------------- | |
minimum time: 224.482 ms (0.93% GC) | |
median time: 231.353 ms (0.92% GC) | |
mean time: 234.625 ms (2.08% GC) | |
maximum time: 290.533 ms (19.53% GC) | |
-------------- | |
samples: 22 | |
evals/sample: 1 | |
############################################################################ | |
############################## Linux & AMD ################################# | |
############################################################################ | |
### cat /proc/cpuinfo gave 2.0 GHz for one core, and 1.4 GHz for the remaining 5. | |
### The cpu fan had failed at one point in this processor's life, possibly damaging it. | |
julia> versioninfo() | |
Julia Version 0.6.0 | |
Commit 9036443 (2017-06-19 13:05 UTC) | |
Platform Info: | |
OS: Linux (x86_64-linux-gnu) | |
CPU: AMD FX(tm)-6300 Six-Core Processor | |
WORD_SIZE: 64 | |
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Piledriver) | |
LAPACK: libopenblas64_ | |
LIBM: libopenlibm | |
LLVM: libLLVM-3.9.1 (ORCJIT, bdver1) | |
julia> vals_j, vecs_j = Julia_eig(H40) | |
([2.74341, 4.00335, 5.0059, 8.16496, 9.08941, 11.9694, 12.1274, 12.7644, 14.2789, 18.5737 … 99.6323, 109.549, 110.885, 120.946, 125.619, 129.633, 140.819, 156.037, 162.288, 186.041], [-0.274927 0.261569 … -0.259847 -0.0474208; 0.0962548 -0.389692 … -0.0260467 0.103609; … ; -0.278481 -0.0513077 … 0.0454802 0.0979261; 0.197902 -0.0335611 … 0.053795 0.00835505]) | |
julia> vals_L, vecs_L = LAPACK_eig(S40) | |
([2.74341, 4.00335, 5.0059, 8.16496, 9.08941, 11.9694, 12.1274, 12.7644, 14.2789, 18.5737 … 99.6323, 109.549, 110.885, 120.946, 125.619, 129.633, 140.819, 156.037, 162.288, 186.041], [-0.274927 -0.261569 … -0.259847 -0.0474208; 0.0962548 0.389692 … -0.0260467 0.103609; … ; -0.278481 0.0513077 … 0.0454802 0.0979261; 0.197902 0.0335611 … 0.053795 0.00835505]) | |
julia> #Eigenvalues are approximately equal. | |
vals_j ≈ vals_L | |
true | |
julia> #Eigenvectors are orthogonal. | |
vecs_j' * vecs_j ≈ eye(40) | |
true | |
julia> vecs_L' * vecs_L ≈ eye(40) | |
true | |
julia> @benchmark Julia_eig($H20) | |
BenchmarkTools.Trial: | |
memory estimate: 11.56 KiB | |
allocs estimate: 24 | |
-------------- | |
minimum time: 88.706 μs (0.00% GC) | |
median time: 89.681 μs (0.00% GC) | |
mean time: 91.207 μs (0.73% GC) | |
maximum time: 1.850 ms (91.26% GC) | |
-------------- | |
samples: 10000 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S20) | |
BenchmarkTools.Trial: | |
memory estimate: 18.03 KiB | |
allocs estimate: 15 | |
-------------- | |
minimum time: 120.944 μs (0.00% GC) | |
median time: 132.230 μs (0.00% GC) | |
mean time: 133.704 μs (0.93% GC) | |
maximum time: 1.908 ms (87.35% GC) | |
-------------- | |
samples: 10000 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H35) | |
BenchmarkTools.Trial: | |
memory estimate: 32.00 KiB | |
allocs estimate: 24 | |
-------------- | |
minimum time: 351.276 μs (0.00% GC) | |
median time: 353.887 μs (0.00% GC) | |
mean time: 358.823 μs (0.44% GC) | |
maximum time: 1.582 ms (72.70% GC) | |
-------------- | |
samples: 10000 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S35) | |
BenchmarkTools.Trial: | |
memory estimate: 43.05 KiB | |
allocs estimate: 15 | |
-------------- | |
minimum time: 319.903 μs (0.00% GC) | |
median time: 353.628 μs (0.00% GC) | |
mean time: 362.566 μs (0.65% GC) | |
maximum time: 27.133 ms (0.00% GC) | |
-------------- | |
samples: 10000 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H40) | |
BenchmarkTools.Trial: | |
memory estimate: 40.91 KiB | |
allocs estimate: 24 | |
-------------- | |
minimum time: 493.866 μs (0.00% GC) | |
median time: 496.545 μs (0.00% GC) | |
mean time: 501.775 μs (0.34% GC) | |
maximum time: 1.646 ms (62.11% GC) | |
-------------- | |
samples: 9925 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S40) | |
BenchmarkTools.Trial: | |
memory estimate: 53.45 KiB | |
allocs estimate: 15 | |
-------------- | |
minimum time: 405.791 μs (0.00% GC) | |
median time: 441.776 μs (0.00% GC) | |
mean time: 452.478 μs (0.54% GC) | |
maximum time: 20.474 ms (0.00% GC) | |
-------------- | |
samples: 10000 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H100) | |
BenchmarkTools.Trial: | |
memory estimate: 240.27 KiB | |
allocs estimate: 27 | |
-------------- | |
minimum time: 6.449 ms (0.00% GC) | |
median time: 6.473 ms (0.00% GC) | |
mean time: 6.529 ms (0.10% GC) | |
maximum time: 7.701 ms (0.00% GC) | |
-------------- | |
samples: 766 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S100) | |
BenchmarkTools.Trial: | |
memory estimate: 272.25 KiB | |
allocs estimate: 19 | |
-------------- | |
minimum time: 2.381 ms (0.00% GC) | |
median time: 2.520 ms (0.00% GC) | |
mean time: 2.703 ms (0.33% GC) | |
maximum time: 36.480 ms (0.00% GC) | |
-------------- | |
samples: 1850 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H133) | |
BenchmarkTools.Trial: | |
memory estimate: 422.23 KiB | |
allocs estimate: 27 | |
-------------- | |
minimum time: 14.639 ms (0.00% GC) | |
median time: 14.827 ms (0.00% GC) | |
mean time: 14.924 ms (0.07% GC) | |
maximum time: 16.660 ms (0.00% GC) | |
-------------- | |
samples: 335 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S133) | |
BenchmarkTools.Trial: | |
memory estimate: 464.77 KiB | |
allocs estimate: 19 | |
-------------- | |
minimum time: 3.815 ms (0.00% GC) | |
median time: 3.965 ms (0.00% GC) | |
mean time: 4.187 ms (0.35% GC) | |
maximum time: 29.175 ms (0.00% GC) | |
-------------- | |
samples: 1194 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H150) | |
BenchmarkTools.Trial: | |
memory estimate: 536.05 KiB | |
allocs estimate: 27 | |
-------------- | |
minimum time: 20.064 ms (0.00% GC) | |
median time: 20.214 ms (0.00% GC) | |
mean time: 20.315 ms (0.06% GC) | |
maximum time: 22.388 ms (0.00% GC) | |
-------------- | |
samples: 247 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S150) | |
BenchmarkTools.Trial: | |
memory estimate: 583.77 KiB | |
allocs estimate: 19 | |
-------------- | |
minimum time: 4.974 ms (0.00% GC) | |
median time: 5.421 ms (0.00% GC) | |
mean time: 5.649 ms (0.31% GC) | |
maximum time: 33.376 ms (0.00% GC) | |
-------------- | |
samples: 885 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H300) | |
BenchmarkTools.Trial: | |
memory estimate: 2.08 MiB | |
allocs estimate: 27 | |
-------------- | |
minimum time: 151.875 ms (0.00% GC) | |
median time: 152.833 ms (0.00% GC) | |
mean time: 153.114 ms (0.03% GC) | |
maximum time: 157.302 ms (0.00% GC) | |
-------------- | |
samples: 33 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S300) | |
BenchmarkTools.Trial: | |
memory estimate: 2.17 MiB | |
allocs estimate: 20 | |
-------------- | |
minimum time: 17.447 ms (0.00% GC) | |
median time: 17.557 ms (0.00% GC) | |
mean time: 18.319 ms (0.34% GC) | |
maximum time: 51.399 ms (0.00% GC) | |
-------------- | |
samples: 273 | |
evals/sample: 1 | |
julia> @benchmark Julia_eig($H1000) | |
BenchmarkTools.Trial: | |
memory estimate: 22.94 MiB | |
allocs estimate: 27 | |
-------------- | |
minimum time: 5.424 s (0.01% GC) | |
median time: 5.424 s (0.01% GC) | |
mean time: 5.424 s (0.01% GC) | |
maximum time: 5.424 s (0.01% GC) | |
-------------- | |
samples: 1 | |
evals/sample: 1 | |
julia> @benchmark LAPACK_eig($S1000) | |
BenchmarkTools.Trial: | |
memory estimate: 23.25 MiB | |
allocs estimate: 20 | |
-------------- | |
minimum time: 254.586 ms (0.25% GC) | |
median time: 257.614 ms (0.25% GC) | |
mean time: 269.437 ms (2.17% GC) | |
maximum time: 341.979 ms (24.85% GC) | |
-------------- | |
samples: 19 | |
evals/sample: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment