Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache friendly strength and degree #2602

Merged
merged 3 commits into from
May 1, 2024

Conversation

gendelpiekel
Copy link
Contributor

Implements #2599. Specifically:

  • faster igraph_degree() when ignoring loops and calculating degree for all vertices,
  • faster igraph_strength() when calculating strength for all vertices,
  • Added benchmark for igraph_strength().

Local benchmark results

igraph_strength() before:

$ ./tests/benchmark_igraph_strength

|  1 igraph_strength(), preferential attachment n=10000, m=10, 100x                 0.03s   0.03s      0s
|  2 igraph_strength(), preferential attachment n=100000, m=10, 100x                0.44s  0.439s      0s
|  3 igraph_strength(), preferential attachment n=100000, m=100, 10x               0.971s  0.971s      0s

igraph_strength() after:

$ ./tests/benchmark_igraph_strength

|  1 igraph_strength(), preferential attachment n=10000, m=10, 100x                0.015s  0.015s      0s
|  2 igraph_strength(), preferential attachment n=100000, m=10, 100x               0.219s  0.219s      0s
|  3 igraph_strength(), preferential attachment n=100000, m=100, 10x               0.284s  0.284s      0s

igraph_degree() before:

$ ./tests/benchmark_igraph_degree

[...]

Do not count loops, O(d) per degree.
|  1 igraph_degree(), preferential attachment n=100000, m=10, 100x                 0.331s  0.331s      0s

igraph_degree() after:

$ ./tests/benchmark_igraph_degree

[...]

Do not count loops, O(d) per degree.
|  1 igraph_degree(), preferential attachment n=100000, m=10, 100x                 0.197s  0.197s      0s

Copy link
Member

@szhorvat szhorvat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is great work! Are you new to igraph, or have you used it before?

The two comments are just an FYI. I'll take care of these and will merge the PR.

If you'd like to be credited using your real name (in addition to your github handle), please let me know what it is.

src/properties/degrees.c Outdated Show resolved Hide resolved
src/properties/degrees.c Outdated Show resolved Hide resolved
Copy link

codecov bot commented May 1, 2024

Codecov Report

Attention: Patch coverage is 97.56098% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 84.29%. Comparing base (c6606ae) to head (c2a6dfa).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2602      +/-   ##
==========================================
- Coverage   84.33%   84.29%   -0.04%     
==========================================
  Files         379      379              
  Lines       61908    61949      +41     
  Branches    12116    12137      +21     
==========================================
+ Hits        52210    52221      +11     
- Misses       9698     9728      +30     
Files Coverage Δ
src/graph/type_indexededgelist.c 95.87% <100.00%> (-0.26%) ⬇️
src/properties/degrees.c 80.97% <96.55%> (-9.41%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6606ae...c2a6dfa. Read the comment docs.

@szhorvat szhorvat merged commit 0e612dc into igraph:master May 1, 2024
23 of 27 checks passed
@szhorvat
Copy link
Member

szhorvat commented May 1, 2024

I updated the benchmarks to compare the previous implementation (b) with this faster code path (a), and I'm getting the following:

|> Benchmark file: /Users/szhorvat/Repos/igraph-main/igraph/tests/benchmarks/igraph_strength.c
|  1a igraph_strength(), preferential attachment n=1000, m=10, 10000x               0.43s  0.422s      0s
|  1b igraph_strength(), preferential attachment n=1000, m=10, 10000x               0.26s  0.256s      0s

|  2a igraph_strength(), preferential attachment n=10000, m=10, 1000x              0.397s  0.392s      0s
|  2b igraph_strength(), preferential attachment n=10000, m=10, 1000x               0.28s  0.276s      0s

|  3a igraph_strength(), preferential attachment n=100000, m=10, 100x              0.422s  0.418s      0s
|  3b igraph_strength(), preferential attachment n=100000, m=10, 100x              0.423s  0.417s      0s

|  4a igraph_strength(), preferential attachment n=100000, m=100, 10x              0.427s  0.421s      0s
|  4b igraph_strength(), preferential attachment n=100000, m=100, 10x              0.868s  0.855s  0.001s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants