Skip to content

Conversation

@shekhirin
Copy link
Contributor

@shekhirin shekhirin commented Jun 17, 2025

Previously benchmarks reused the same static data for all iterations, which could lead to unrealistic performance measurements due to cache effects and lack of input variation.

Now we use proptest::arbitrary to generate random data.

shekhirin and others added 2 commits June 17, 2025 13:19
Previously benchmarks reused the same static data for all iterations,
which could lead to unrealistic performance measurements due to cache
effects and lack of input variation.

Changes:
- Add rand dependency for random data generation
- Replace static data setup with iter_batched pattern
- Generate fresh random inputs for each benchmark iteration
- Update all 20+ benchmark functions to use random inputs
- Remove unused helper functions

This ensures more realistic and robust performance measurements
by testing with varied inputs on each iteration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@codspeed-hq
Copy link

codspeed-hq bot commented Jun 17, 2025

CodSpeed Performance Report

Merging #25 will degrade performances by 98.5%

Comparing alexey/fix-benchmark-random-inputs (a4c8884) with main (866d3f7)

Summary

❌ 62 regressions
✅ 8 untouched benchmarks
🆕 20 new benchmarks
⁉️ 45 dropped benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
clone[16] 335.3 ns 8,894.7 ns -96.23%
clone[32] 306.4 ns 8,893.3 ns -96.55%
clone[64] 306.4 ns 8,893.3 ns -96.55%
clone[8] 335.8 ns 8,950.3 ns -96.25%
cmp[16] 305.8 ns 8,861.4 ns -96.55%
cmp[32] 303.6 ns 8,550 ns -96.45%
cmp[64] 303.6 ns 8,579.2 ns -96.46%
cmp[8] 305.8 ns 8,825.6 ns -96.53%
common_prefix_length[16] 251.4 ns 10,220.3 ns -97.54%
common_prefix_length[32] 295.8 ns 13,048.1 ns -97.73%
common_prefix_length[64] 384.7 ns 16,682.8 ns -97.69%
common_prefix_length[8] 200 ns 9,120.3 ns -97.81%
ends_with[16] 276.9 ns 8,887.5 ns -96.88%
ends_with[32] 276.9 ns 8,870.3 ns -96.88%
ends_with[64] 276.9 ns 8,955 ns -96.91%
ends_with[8] 276.9 ns 8,782.8 ns -96.85%
extend[16] 466.4 ns 11,050 ns -95.78%
extend[32] 466.7 ns 11,105.6 ns -95.8%
extend[8] 496.1 ns 11,190.3 ns -95.57%
first[16] 150.8 ns 4,367.5 ns -96.55%
... ... ... ... ...

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

@shekhirin shekhirin marked this pull request as ready for review June 17, 2025 13:24
@shekhirin shekhirin changed the title fix: generate random inputs for each benchmark iteration test: generate random inputs for each benchmark iteration Jun 17, 2025
@shekhirin shekhirin changed the title test: generate random inputs for each benchmark iteration bench: generate random inputs for each benchmark iteration Jun 17, 2025
benches/bench.rs Outdated
b.iter(|| Nibbles::from_nibbles(black_box(data)))
group.bench_function(BenchmarkId::from_parameter(size), |b| {
b.iter_batched(
|| generate_nibbles_random(size),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense but this will only work locally; codspeed only uses 1 input regardless of the function used. See ruint benchmarks for a wrapper to run multiple times on codspeed

@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch 4 times, most recently from df4a3bb to 9020723 Compare June 17, 2025 17:04
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch 3 times, most recently from 1eb3f92 to 1a1cf4e Compare June 17, 2025 17:08
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch from 1a1cf4e to 3cfe0b4 Compare June 17, 2025 17:09
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch from 080f9d7 to 081e9e9 Compare June 17, 2025 18:43
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch 2 times, most recently from 29160ef to c0ea65f Compare June 17, 2025 18:48
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch from c0ea65f to 1d396d8 Compare June 17, 2025 18:51
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch from 1d396d8 to 122ba17 Compare June 17, 2025 19:16
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch from ab8c5a8 to 6e61d1f Compare June 18, 2025 09:23
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch from 6e61d1f to 16c4dd2 Compare June 18, 2025 09:31
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch 2 times, most recently from 6afa918 to 72a1ec9 Compare June 18, 2025 09:47
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch from 72a1ec9 to 4c5bfa2 Compare June 18, 2025 09:47
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch from 5acfa7e to b7e8c75 Compare June 18, 2025 09:49
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch 8 times, most recently from 5d98fce to 0c76a10 Compare June 18, 2025 10:08
@shekhirin shekhirin force-pushed the alexey/fix-benchmark-random-inputs branch from dddf790 to 776bc31 Compare June 18, 2025 10:17
@shekhirin shekhirin marked this pull request as draft June 19, 2025 11:11
#[inline]
fn manual_batch<T, U>(mut setup: impl FnMut() -> T, mut f: impl FnMut(&T) -> U) -> impl FnMut(T) {
let inputs =
criterion::black_box((0..CODSPEED_BATCH_SIZE).map(|_| setup()).collect::<Vec<_>>());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use std::hint::black_box

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.

3 participants