## Question of the day... (performance)
# Is it faster to use CSC or Dense form when doing mat-vecs
# when the underlying matrix is dense.
A = randn(10,10)
M = A'*A
10×10 Matrix{Float64}: 7.19437 0.262321 3.5965 … -1.53133 1.72482 2.21619 0.262321 3.50882 -1.35676 1.24194 1.66241 0.763377 3.5965 -1.35676 8.46277 1.79399 2.02498 3.77358 1.11312 -0.850809 -2.38092 -4.12616 2.08811 -1.14009 -0.104661 -1.39731 4.99816 -0.339351 4.29163 4.01622 3.16547 0.177832 1.22352 … -2.84019 -0.364124 0.334475 0.309036 -2.28611 1.41009 1.38116 -1.35448 0.00906399 -1.53133 1.24194 1.79399 12.8209 -3.59556 -4.58151 1.72482 1.66241 2.02498 -3.59556 7.65084 3.55106 2.21619 0.763377 3.77358 -4.58151 3.55106 8.94372
##
using SparseArrays
S = sparse(M)
10×10 SparseMatrixCSC{Float64, Int64} with 100 stored entries: 7.19437 0.262321 3.5965 … -1.53133 1.72482 2.21619 0.262321 3.50882 -1.35676 1.24194 1.66241 0.763377 3.5965 -1.35676 8.46277 1.79399 2.02498 3.77358 1.11312 -0.850809 -2.38092 -4.12616 2.08811 -1.14009 -0.104661 -1.39731 4.99816 -0.339351 4.29163 4.01622 3.16547 0.177832 1.22352 … -2.84019 -0.364124 0.334475 0.309036 -2.28611 1.41009 1.38116 -1.35448 0.00906399 -1.53133 1.24194 1.79399 12.8209 -3.59556 -4.58151 1.72482 1.66241 2.02498 -3.59556 7.65084 3.55106 2.21619 0.763377 3.77358 -4.58151 3.55106 8.94372
##
n = 10
10
##
using BenchmarkTools, SparseArrays
@benchmark A*v setup=begin
A = randn(n,n)
v = randn(n)
end
BenchmarkTools.Trial: 10000 samples with 958 evaluations. Range (min … max): 90.902 ns … 2.512 μs ┊ GC (min … max): 0.00% … 0.00% Time (median): 91.946 ns ┊ GC (median): 0.00% Time (mean ± σ): 95.079 ns ± 36.083 ns ┊ GC (mean ± σ): 0.59% ± 3.46% ▇█▆▅▃▁ ▁▇▆▅▃▂▁ ▂ ██████▇███████████████▇▇▇▇▆▇▇▇▆▅▆▆▅▆▄▆▅▅▅▅▄▆▄▅▅▄▁▄▄▃▁▁▃▄▅▃▄ █ 90.9 ns Histogram: log(frequency) by time 117 ns < Memory estimate: 144 bytes, allocs estimate: 1.
##
using BenchmarkTools
@benchmark A*v setup=begin
A = sparse(randn(n,n))
v = randn(n)
end
BenchmarkTools.Trial: 10000 samples with 962 evaluations. Range (min … max): 84.936 ns … 338.921 ns ┊ GC (min … max): 0.00% … 69.90% Time (median): 91.000 ns ┊ GC (median): 0.00% Time (mean ± σ): 91.013 ns ± 12.031 ns ┊ GC (mean ± σ): 0.62% ± 3.52% ▁▄██▆▃ ▂▃▃▆▇█▇▅▃▁ ▂▂▃▂▂▁▁▁ ▂ ███████████████████████████████████▇▆▇▇▇███▆▇▇▇▇▆▆▆▅▅▄▂▄▄▅▅▄ █ 84.9 ns Histogram: log(frequency) by time 111 ns < Memory estimate: 144 bytes, allocs estimate: 1.