Skip to content

Run benchmarks with CodSpeed in CI - #1

Open
codspeed[bot] wants to merge 1 commit into
masterfrom
codspeed/setup-benchmarks
Open

codspeed[bot] wants to merge 1 commit into
masterfrom
codspeed/setup-benchmarks

Conversation

@codspeed

@codspeed codspeed Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

This sets up CodSpeed so every pull request gets a performance report that compares its benchmarks with master.

What changed

Existing benchmarks, now on stable Rust. The benchmarks in benches/ and ndarray-rand/benches/ used nightly-only libtest #[bench]. They now use the bencher API through codspeed-bencher-compat (a dev-dependency renamed to bencher). The benchmark bodies are unchanged. The port is mechanical:

  • #![feature(test)] / extern crate test removed; test::black_box replaced by std::hint::black_box.
  • #[bench] attributes replaced by a benchmark_group! / benchmark_main! at the end of each file, and [[bench]] harness = false entries in Cargo.toml.
  • par_rayon uses required-features = ["rayon"] instead of a crate-level #![cfg(feature = "rayon")].
  • The mat_mul! benchmarks are registered with their module path (mat_mul_f32::m004, ...), so the f32, f64 and i32 variants keep distinct names.

Outside of CodSpeed, cargo bench still works and uses the plain bencher crate, now on any toolchain.

CI. A new .github/workflows/codspeed.yaml builds and runs the benchmarks in CodSpeed's CPU simulation mode on pushes to master, on pull requests, and on manual dispatch. It authenticates with OIDC, so no secret token is needed.

README. A CodSpeed badge, and a short "Benchmarks" section with the local command:

cargo codspeed build -m simulation -p ndarray -p ndarray-rand -F ndarray/rayon
cargo codspeed run -p ndarray -p ndarray-rand

Results

The CodSpeed workflow passed on this pull request, and the CodSpeed report lists 229 new benchmarks (232 run, see below for the 3 others). A local run gave the same set: run report.

Notes:

  • bench1.rs::into_dimensionality_ix1_ok, into_dimensionality_ix3_ok and into_dimensionality_ix3_err measure under 1 ns: the compiler removes the code under test. This port does not change their code. Wrapping their inputs and outputs in black_box would fix it.
  • Most par_rayon.rs benchmarks are flagged as dominated by system calls (thread synchronization). Simulation excludes system calls, so these numbers understate the real multi-threaded cost. Walltime would measure them better, but walltime needs CodSpeed macro runners, which are not available on personal accounts. On ubuntu-latest, walltime results vary much more than on macro runners.

Existing CI failures

The "Continuous integration" workflow fails on this pull request, but the same jobs already fail on master and the errors are not in the benchmark code:

  • tests/*, cross_test/* and cargo-careful stop on tests/numeric.rs, which uses the deprecated std::f64::NAN while RUSTFLAGS has -D warnings.
  • clippy/stable stops on new clippy lints in src/ and a removed lint name.

Comment this and I'll do it:

@codspeedbot fix the into_dimensionality benchmarks that the compiler optimizes out

…d CI

Port the nightly libtest #[bench] benchmarks to the bencher API through
codspeed-bencher-compat, so they build on stable Rust and CodSpeed can
measure them. Add a CodSpeed workflow that runs them in simulation mode on
pushes to master and on pull requests, and a CodSpeed badge in the README.
@codspeed

codspeed Bot commented Nov 26, 2026

Copy link
Copy Markdown
Author

Congrats! CodSpeed is installed 🎉

🆕 229 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

2 warnings

⚠️ Unable to measure the execution of 3 benchmarks

These benchmarks measured no execution time, so their results are not comparable and count as unchanged. This usually happens when the compiler removes the code under test.

Prevent compiler optimizations

See affected benchmarks

⚠️ 8 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

Detected benchmarks


ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.


Open in CodSpeed

@codspeed
codspeed Bot requested a review from akern40 November 26, 2026 22:15
@codspeed
codspeed Bot marked this pull request as ready for review November 26, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants