Skip to content

contrib: migrate benchmarks from nightly libtest to criterion#1310

Open
TheAwiteb wants to merge 2 commits into
nostrdevkit:masterfrom
TheAwiteb:criterion-for-benches
Open

contrib: migrate benchmarks from nightly libtest to criterion#1310
TheAwiteb wants to merge 2 commits into
nostrdevkit:masterfrom
TheAwiteb:criterion-for-benches

Conversation

@TheAwiteb

Copy link
Copy Markdown
Member

This PR moves the benchmark suite to /benches so it can be run with cargo bench -p benches on stable Rust. It also provides an HTML report in target/criterion/report/index.html.

While porting, several bugs in the existing benchmarks were identified and fixed:

  • public_key_to_hex: was incorrectly benchmarking PublicKey::to_bech32 instead of PublicKey::to_hex.
  • tags_dedup_**_tags: were deduplicating already-deduplicated tags; fixed by using Bencher::iter_batched to supply fresh tags each iteration.
  • tags_pop and vec_tags_pop: were popping from an already-empty collection; now reset the collection per iteration.
  • tags_push and vec_tags_push: were unnecessarily allocating on each iteration instead of reusing pre‑allocated space.

Notes to the reviewers

I exported InnerRelay and InnerRelay::handle_raw_relay_message if bench is enabled

Checklist

@TheAwiteb TheAwiteb requested a review from yukibtc as a code owner March 27, 2026 19:26
@codecov

codecov Bot commented Mar 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.74%. Comparing base (c24f879) to head (e936030).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1310      +/-   ##
==========================================
- Coverage   69.75%   69.74%   -0.01%     
==========================================
  Files         188      188              
  Lines       31391    31393       +2     
==========================================
- Hits        21897    21896       -1     
- Misses       9494     9497       +3     
Flag Coverage Δ
rust 69.74% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TheAwiteb TheAwiteb force-pushed the criterion-for-benches branch 5 times, most recently from f2e5418 to bad3ba2 Compare March 27, 2026 21:55
This commit moves the benchmark suite to `/benches` so it can be run
with `cargo bench -p benches` on stable Rust. It also provides an HTML
report in `target/criterion/report/index.html`.

While porting, several bugs in the existing benchmarks were identified
and fixed:

- `public_key_to_hex`: was incorrectly benchmarking
  `PublicKey::to_bech32` instead of `PublicKey::to_hex`.
- `tags_dedup_**_tags`: were deduplicating already-deduplicated tags;
  fixed by using `Bencher::iter_batched` to supply fresh tags each
  iteration.
- `tags_pop` and `vec_tags_pop`: were popping from an already-empty
  collection; now reset the collection per iteration.
- `tags_push` and `vec_tags_push`: were unnecessarily allocating on each
  iteration instead of reusing pre‑allocated space.

Signed-off-by: Awiteb <a@4rs.nl>
@TheAwiteb TheAwiteb force-pushed the criterion-for-benches branch from bad3ba2 to c2f4208 Compare March 27, 2026 22:17
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.

1 participant