Skip to content

Commit ef8e393

Browse files
Jacob Zhongclaude
andcommitted
Add ubig_sqr benchmark covering all algorithm thresholds
Tests 10^1 through 10^6 bit random operands, exercising simple, Karatsuba, Toom-3, and NTT squaring paths. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 54411c8 commit ef8e393

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

integer/benches/primitive.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,27 @@ fn ubig_mul_asymmetric(criterion: &mut Criterion) {
175175
group.finish();
176176
}
177177

178+
fn ubig_sqr(criterion: &mut Criterion) {
179+
let mut rng = StdRng::seed_from_u64(SEED);
180+
let mut group = criterion.benchmark_group("ubig_sqr");
181+
group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
182+
183+
for log_bits in 1..=6 {
184+
if log_bits >= 5 {
185+
group.sample_size(10);
186+
}
187+
let bits = 10usize.pow(log_bits);
188+
let a = random_ubig(bits, &mut rng);
189+
group.bench_with_input(
190+
BenchmarkId::from_parameter(format!("1e{}", log_bits)),
191+
&a,
192+
|bencher, ta| bencher.iter(|| ta.sqr()),
193+
);
194+
}
195+
196+
group.finish();
197+
}
198+
178199
criterion_group!(
179200
benches,
180201
ubig_add,
@@ -189,6 +210,7 @@ criterion_group!(
189210
ubig_pow_large_base,
190211
ubig_ilog_large,
191212
ubig_mul_asymmetric,
213+
ubig_sqr,
192214
);
193215

194216
criterion_main!(benches);

0 commit comments

Comments
 (0)