Skip to content

Commit

Permalink
Added benchmark action with pytest-benchmark (#630)
Browse files Browse the repository at this point in the history
* updates

* Update benchmark.yml

* Update benchmark.yml

* Update benchmark.yml

* Update bench.py
  • Loading branch information
nwlandry authored Nov 24, 2024
1 parent f2624e1 commit d7ba0a7
Show file tree
Hide file tree
Showing 11 changed files with 174,074 additions and 463 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Benchmark XGI
on:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: write
deployments: write

jobs:
benchmark:
name: Run pytest-benchmark benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.13
- name: Run benchmarks
run: |
cd benchmarks
pip install --upgrade pip
pip install .[benchmark]
pytest bench.py --benchmark-json output.json
- name: Store benchmark results
uses: benchmark-action/github-action-benchmark@v1
with:
name: Python Benchmark with pytest-benchmark
tool: 'pytest'
output-file-path: benchmarks/output.json
# Use personal access token instead of GITHUB_TOKEN due to https://github.saobby.my.eu.orgmunity/t/github-action-not-triggering-gh-pages-upon-push/16096
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
comment-on-alert: false
fail-on-alert: true
163 changes: 163 additions & 0 deletions benchmarks/bench.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import random

import numpy as np
import pandas as pd
import pytest

import xgi


def test_construct_from_edgelist(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H.edges.members(),), {}

benchmark.pedantic(xgi.Hypergraph, setup=setup, rounds=10)


def test_construct_from_edgedict(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H.edges.members(dtype=dict),), {}

benchmark.pedantic(xgi.Hypergraph, setup=setup, rounds=10)


def test_construct_from_df(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (xgi.to_bipartite_pandas_dataframe(H),), {}

benchmark.pedantic(xgi.Hypergraph, setup=setup, rounds=10)


def test_node_memberships(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def node_memberships(H):
[H.nodes.memberships(n) for n in H.nodes]

benchmark.pedantic(node_memberships, setup=setup, rounds=10)


def test_edge_members(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def edge_members(H):
[H.edges.members(eid) for eid in H.edges]

benchmark.pedantic(edge_members, setup=setup, rounds=10)


def test_node_attributes(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def node_attributes(H):
[H.nodes[nid] for nid in H.nodes]

benchmark.pedantic(node_attributes, setup=setup, rounds=10)


def test_edge_attributes(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def edge_attributes(H):
[H.edges[eid] for eid in H.edges]

benchmark.pedantic(edge_attributes, setup=setup, rounds=10)


def test_degree(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def degree(H):
H.degree()

benchmark.pedantic(degree, setup=setup, rounds=10)


def test_nodestats_degree(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def degree(H):
H.nodestats.degree.asnumpy()

benchmark.pedantic(degree, setup=setup, rounds=10)


def test_nodestats_degree(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def degree(H):
H.nodes.degree.asnumpy()

benchmark.pedantic(degree, setup=setup, rounds=10)


def test_edge_size(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def degree(H):
H.edges.size.asnumpy()

benchmark.pedantic(degree, setup=setup, rounds=10)


def test_isolates(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def isolates(H):
H.nodes.isolates()

benchmark.pedantic(isolates, setup=setup, rounds=10)


def test_singletons(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def singletons(H):
H.edges.singletons()

benchmark.pedantic(singletons, setup=setup, rounds=10)


def test_copy(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def copy(H):
H.copy()

benchmark.pedantic(copy, setup=setup, rounds=10)


def test_dual(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def dual(H):
H.dual()

benchmark.pedantic(dual, setup=setup, rounds=10)
1 change: 0 additions & 1 deletion benchmarks/benchmarks/__init__.py

This file was deleted.

55 changes: 0 additions & 55 deletions benchmarks/benchmarks/bench_core_hypergraph.py

This file was deleted.

15 changes: 0 additions & 15 deletions benchmarks/benchmarks/common.py

This file was deleted.

Loading

0 comments on commit d7ba0a7

Please sign in to comment.