Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

modified laplacian_matrix to achieve speed-up #1191

Merged
merged 6 commits into from
Apr 4, 2019

Conversation

dahtah
Copy link
Contributor

@dahtah dahtah commented Apr 1, 2019

For some reason sparse + Diagonal is very slow. Modified laplacian_matrix to use sparse + sparse instead. This achieves a 100x speed-up in some cases.

@dahtah
Copy link
Contributor Author

dahtah commented Apr 1, 2019

Ref: #1168

@codecov
Copy link

codecov bot commented Apr 1, 2019

Codecov Report

Merging #1191 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1191      +/-   ##
==========================================
+ Coverage   99.62%   99.62%   +<.01%     
==========================================
  Files          93       93              
  Lines        4270     4271       +1     
==========================================
+ Hits         4254     4255       +1     
  Misses         16       16

@sbromberger
Copy link
Owner

Could you post some benchmarks?

src/linalg/spectral.jl Outdated Show resolved Hide resolved
src/linalg/spectral.jl Outdated Show resolved Hide resolved
@dahtah
Copy link
Contributor Author

dahtah commented Apr 2, 2019

Here are some numbers (v1.0.3 on Linux). On some graphs the gain is massive. For

G = Grid([50,50])

The old version gives:

BenchmarkTools.Trial: 
  memory estimate:  1.07 MiB
  allocs estimate:  2571
  --------------
  minimum time:     16.163 ms (0.00% GC)
  median time:      16.205 ms (0.00% GC)
  mean time:        16.508 ms (1.55% GC)
  maximum time:     67.344 ms (75.87% GC)
  --------------
  samples:          303
  evals/sample:     1

and the new

BenchmarkTools.Trial: 
  memory estimate:  914.52 KiB
  allocs estimate:  2560
  --------------
  minimum time:     272.325 μs (0.00% GC)
  median time:      277.983 μs (0.00% GC)
  mean time:        338.724 μs (16.49% GC)
  maximum time:     50.634 ms (99.29% GC)
  --------------
  samples:          10000
  evals/sample:     1

On

G = Grid([30,30,30])

Old:

BenchmarkTools.Trial: 
  memory estimate:  11.96 MiB
  allocs estimate:  27074
  --------------
  minimum time:     1.845 s (0.00% GC)
  median time:      1.877 s (0.00% GC)
  mean time:        1.867 s (0.23% GC)
  maximum time:     1.879 s (0.00% GC)
  --------------
  samples:          3
  evals/sample:     1

New:

BenchmarkTools.Trial: 
  memory estimate:  11.57 MiB
  allocs estimate:  27060
  --------------
  minimum time:     5.150 ms (0.00% GC)
  median time:      5.881 ms (6.01% GC)
  mean time:        5.727 ms (7.57% GC)
  maximum time:     59.003 ms (89.62% GC)
  --------------
  samples:          872
  evals/sample:     1

On other graphs the difference is less spectacular but still significant:

G = SimpleDiGraph(1000,10000)

Old:

BenchmarkTools.Trial: 
  memory estimate:  2.89 MiB
  allocs estimate:  14782
  --------------
  minimum time:     4.098 ms (0.00% GC)
  median time:      4.164 ms (0.00% GC)
  mean time:        4.418 ms (5.01% GC)
  maximum time:     55.348 ms (92.26% GC)
  --------------
  samples:          1131
  evals/sample:     1

New:

BenchmarkTools.Trial: 
  memory estimate:  2.87 MiB
  allocs estimate:  14772
  --------------
  minimum time:     1.496 ms (0.00% GC)
  median time:      1.556 ms (0.00% GC)
  mean time:        1.758 ms (10.77% GC)
  maximum time:     52.933 ms (96.66% GC)
  --------------
  samples:          2838
  evals/sample:     1

@sbromberger
Copy link
Owner

These benchmarks are really compelling. Thanks.

@sbromberger sbromberger merged commit 5b1cdc9 into sbromberger:master Apr 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants