Skip to content

Commit

Permalink
add codspeed benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Sep 6, 2023
1 parent 218a595 commit 0034ce6
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 23 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/benches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: benches

on:
push:
branches:
- "main"
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@v4
- uses: dtolnay/rust-toolchain@stable

- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
pyo3-benches/target
target
key: cargo-${{ runner.os }}-bench-${{ hashFiles('**/Cargo.toml') }}
continue-on-error: true

- name: Install cargo-codspeed
run: cargo install cargo-codspeed

- name: Install nox
run: pip install nox

- name: Run the benchmarks
uses: CodSpeedHQ/action@v1
with:
run: nox -s codspeed
token: ${{ secrets.CODSPEED_TOKEN }}
13 changes: 13 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ def bench(session: nox.Session) -> bool:
_run_cargo(session, "bench", _BENCHES, *session.posargs)


@nox.session()
def codspeed(session: nox.Session) -> bool:
# rust benchmarks
os.chdir(PYO3_DIR / "pyo3-benches")
_run_cargo(session, "codspeed", "build")
_run_cargo(session, "codspeed", "run")
# python benchmarks
os.chdir(PYO3_DIR / "pytests")
session.install("-r", "requirements-dev.txt", "pytest-codspeed")
session.install(".")
_run(session, "pytest", "--codspeed", external=True)


@nox.session(name="clippy-all", venv_backend="none")
def clippy_all(session: nox.Session) -> None:
success = True
Expand Down
10 changes: 3 additions & 7 deletions pyo3-benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ edition = "2021"
publish = false

[dependencies]
pyo3 = { path = "../", features = ["auto-initialize"] }
pyo3 = { path = "../", features = ["auto-initialize", "full"] }

[dev-dependencies]
codspeed-criterion-compat = "2.2"
criterion = "0.5.1"
num-bigint = "0.4.3"
rust_decimal = { version = "1.0.0", default-features = false }

[[bench]]
name = "bench_any"
Expand All @@ -32,17 +34,14 @@ harness = false
[[bench]]
name = "bench_decimal"
harness = false
required-features = ["pyo3/rust_decimal"]

[[bench]]
name = "bench_dict"
harness = false
required-features = ["pyo3/hashbrown"]

[[bench]]
name = "bench_frompyobject"
harness = false
required-features = ["pyo3/macros"]

[[bench]]
name = "bench_gil"
Expand All @@ -55,7 +54,6 @@ harness = false
[[bench]]
name = "bench_pyclass"
harness = false
required-features = ["pyo3/macros"]

[[bench]]
name = "bench_pyobject"
Expand All @@ -64,7 +62,6 @@ harness = false
[[bench]]
name = "bench_set"
harness = false
required-features = ["pyo3/hashbrown"]

[[bench]]
name = "bench_tuple"
Expand All @@ -81,6 +78,5 @@ harness = false
[[bench]]
name = "bench_bigint"
harness = false
required-features = ["pyo3/num-bigint"]

[workspace]
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_any.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::{
types::{
Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_bigint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion};

use pyo3::{types::PyDict, PyAny, Python};

Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_comparisons.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::{prelude::*, pyclass::CompareOp, Python};

Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_decimal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion};

use pyo3::prelude::*;
use pyo3::types::PyDict;
Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_dict.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::types::IntoPyDict;
use pyo3::{prelude::*, types::PyMapping};
Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_err.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::{exceptions::PyValueError, prelude::*};

Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_extract.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion};

use pyo3::{
types::{PyDict, PyFloat, PyInt, PyString},
Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_frompyobject.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion};

use pyo3::{
prelude::*,
Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_gil.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, BatchSize, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Bencher, Criterion};

use pyo3::{prelude::*, GILPool};

Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_intern.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::prelude::*;
use pyo3::types::{PyList, PySequence};
Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_pyclass.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
use pyo3::{impl_::pyclass::LazyTypeObject, prelude::*};

/// This is a feature-rich class instance used to benchmark various parts of the pyclass lifecycle.
Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_pyobject.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_set.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::prelude::*;
use pyo3::types::PySet;
Expand Down
2 changes: 1 addition & 1 deletion pyo3-benches/benches/bench_tuple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::prelude::*;
use pyo3::types::{PyList, PySequence, PyTuple};
Expand Down

0 comments on commit 0034ce6

Please sign in to comment.