From 2119a65a11b02be0504d1be0d58b57c2391841ab Mon Sep 17 00:00:00 2001 From: Jordan Matelsky Date: Wed, 17 Apr 2024 10:37:15 -0400 Subject: [PATCH 1/7] Add benchmarking --- .github/workflows/codspeed.yml | 28 ++++++++++++++++++++++++++++ grand/backends/test_backends.py | 22 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 .github/workflows/codspeed.yml diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 0000000..7969ee2 --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,28 @@ +name: codspeed-benchmarks + +on: + push: + branches: + - "master" + pull_request: + # `workflow_dispatch` allows CodSpeed to trigger backtest + # performance analysis in order to generate initial data. + workflow_dispatch: + +jobs: + benchmarks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + with: + python-version: "3.11" + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run benchmarks + uses: CodSpeedHQ/action@v2 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: pytest tests/ --codspeed \ No newline at end of file diff --git a/grand/backends/test_backends.py b/grand/backends/test_backends.py index 55ffd7d..a44e0f4 100644 --- a/grand/backends/test_backends.py +++ b/grand/backends/test_backends.py @@ -369,3 +369,25 @@ def test_directed_degree_multiple(self, backend): assert G.nx.in_degree("foo") == 0 assert G.nx.in_degree("bar") == 1 assert G.nx.in_degree("baz") == 1 + + +@pytest.mark.benchmark +@pytest.mark.parametrize("backend", backend_test_params) +def test_node_addition_performance(backend): + backend, kwargs = backend + G = Graph(backend=backend(directed=True, **kwargs)) + for i in range(10000): + G.nx.add_node(i) + assert len(G.nx) == 10000 + + +@pytest.mark.benchmark +@pytest.mark.parametrize("backend", backend_test_params) +def test_get_density_performance(backend): + backend, kwargs = backend + G = Graph(backend=backend(directed=True, **kwargs)) + for i in range(10000): + G.nx.add_node(i) + for i in range(10000 - 1): + G.nx.add_edge(i, i + 1) + assert nx.density(G.nx) <= 0.005 From 8c4de83b55df507e9aaba391eae33bb2767e82b0 Mon Sep 17 00:00:00 2001 From: Jordan Matelsky Date: Wed, 17 Apr 2024 10:37:50 -0400 Subject: [PATCH 2/7] Update CI for benchmarking --- .github/workflows/codspeed.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index 7969ee2..796f137 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -19,7 +19,7 @@ jobs: python-version: "3.11" - name: Install dependencies - run: pip install -r requirements.txt + run: pip install -r requirements.txt && pip install pytest pytest-codspeed - name: Run benchmarks uses: CodSpeedHQ/action@v2 From 1771d3e5a2e79b6fd27b5cfc22307a2f39421a32 Mon Sep 17 00:00:00 2001 From: Jordan Matelsky Date: Wed, 17 Apr 2024 10:39:17 -0400 Subject: [PATCH 3/7] Fix dep installation --- .github/workflows/codspeed.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index 796f137..aa622b8 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -19,7 +19,12 @@ jobs: python-version: "3.11" - name: Install dependencies - run: pip install -r requirements.txt && pip install pytest pytest-codspeed + run: | + python -m pip install --upgrade pip + pip install flake8 pytest pytest-cov pytest-codspeed + # Install "cmake", "cython" for networkit. Must happen first: + pip install --upgrade cmake cython + pip install -e ".[sql,networkit,igraph]" - name: Run benchmarks uses: CodSpeedHQ/action@v2 From 9768c53f0fdfd8f5d5a02e491a246cabf7bbffbf Mon Sep 17 00:00:00 2001 From: Jordan Matelsky Date: Wed, 17 Apr 2024 10:40:24 -0400 Subject: [PATCH 4/7] yml syntax... --- .github/workflows/codspeed.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index aa622b8..a22e2af 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -19,12 +19,12 @@ jobs: python-version: "3.11" - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest pytest-cov pytest-codspeed - # Install "cmake", "cython" for networkit. Must happen first: - pip install --upgrade cmake cython - pip install -e ".[sql,networkit,igraph]" + run: | + python -m pip install --upgrade pip + pip install flake8 pytest pytest-cov pytest-codspeed + # Install "cmake", "cython" for networkit. Must happen first: + pip install --upgrade cmake cython + pip install -e ".[sql,networkit,igraph]" - name: Run benchmarks uses: CodSpeedHQ/action@v2 From 864da97d17b00da9f878c2e1f2b7ecfd36449b1f Mon Sep 17 00:00:00 2001 From: Jordan Matelsky Date: Wed, 17 Apr 2024 10:42:22 -0400 Subject: [PATCH 5/7] Fix default codspeed yml --- .github/workflows/codspeed.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index a22e2af..ef133e8 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -23,11 +23,11 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest pytest-cov pytest-codspeed # Install "cmake", "cython" for networkit. Must happen first: - pip install --upgrade cmake cython + pip install --upgrade cmake cython pip install -e ".[sql,networkit,igraph]" - name: Run benchmarks uses: CodSpeedHQ/action@v2 with: token: ${{ secrets.CODSPEED_TOKEN }} - run: pytest tests/ --codspeed \ No newline at end of file + run: pytest . --codspeed \ No newline at end of file From db744a135e96a93cdb1f857c45d275fcaff4b286 Mon Sep 17 00:00:00 2001 From: Jordan Matelsky Date: Wed, 17 Apr 2024 11:31:21 -0400 Subject: [PATCH 6/7] Try without token --- .github/workflows/codspeed.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index ef133e8..54431d2 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -29,5 +29,5 @@ jobs: - name: Run benchmarks uses: CodSpeedHQ/action@v2 with: - token: ${{ secrets.CODSPEED_TOKEN }} + # token: ${{ secrets.CODSPEED_TOKEN }} run: pytest . --codspeed \ No newline at end of file From 0850485e14d111c7384ee7623c05bee308f04a05 Mon Sep 17 00:00:00 2001 From: Jordan Matelsky Date: Wed, 17 Apr 2024 13:06:30 -0400 Subject: [PATCH 7/7] Try to track down codspeed failure --- .github/workflows/codspeed.yml | 2 +- grand/backends/test_backends.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index 54431d2..05389bc 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -24,7 +24,7 @@ jobs: pip install flake8 pytest pytest-cov pytest-codspeed # Install "cmake", "cython" for networkit. Must happen first: pip install --upgrade cmake cython - pip install -e ".[sql,networkit,igraph]" + pip install -e ".[sql]" - name: Run benchmarks uses: CodSpeedHQ/action@v2 diff --git a/grand/backends/test_backends.py b/grand/backends/test_backends.py index a44e0f4..18f4c52 100644 --- a/grand/backends/test_backends.py +++ b/grand/backends/test_backends.py @@ -376,9 +376,9 @@ def test_directed_degree_multiple(self, backend): def test_node_addition_performance(backend): backend, kwargs = backend G = Graph(backend=backend(directed=True, **kwargs)) - for i in range(10000): + for i in range(1000): G.nx.add_node(i) - assert len(G.nx) == 10000 + assert len(G.nx) == 1000 @pytest.mark.benchmark @@ -386,8 +386,8 @@ def test_node_addition_performance(backend): def test_get_density_performance(backend): backend, kwargs = backend G = Graph(backend=backend(directed=True, **kwargs)) - for i in range(10000): + for i in range(1000): G.nx.add_node(i) - for i in range(10000 - 1): + for i in range(1000 - 1): G.nx.add_edge(i, i + 1) assert nx.density(G.nx) <= 0.005