-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added benchmark action with pytest-benchmark (#630)
* updates * Update benchmark.yml * Update benchmark.yml * Update benchmark.yml * Update bench.py
- Loading branch information
Showing
11 changed files
with
174,074 additions
and
463 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.