From 4438409a68e82a71c29d2269567c66408ee9a493 Mon Sep 17 00:00:00 2001 From: Jordan Matelsky Date: Wed, 17 Apr 2024 13:14:11 -0400 Subject: [PATCH] Add codspeed (#48) * Add benchmarking * Update CI for benchmarking * Fix dep installation * yml syntax... * Fix default codspeed yml * Try without token * Try to track down codspeed failure --- .github/workflows/codspeed.yml | 33 +++++++++++++++++++++++++++++++++ grand/backends/test_backends.py | 22 ++++++++++++++++++++++ 2 files changed, 55 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..05389bc --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,33 @@ +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: | + 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]" + + - name: Run benchmarks + uses: CodSpeedHQ/action@v2 + with: + # token: ${{ secrets.CODSPEED_TOKEN }} + run: pytest . --codspeed \ No newline at end of file diff --git a/grand/backends/test_backends.py b/grand/backends/test_backends.py index 55ffd7d..18f4c52 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(1000): + G.nx.add_node(i) + assert len(G.nx) == 1000 + + +@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(1000): + G.nx.add_node(i) + for i in range(1000 - 1): + G.nx.add_edge(i, i + 1) + assert nx.density(G.nx) <= 0.005