Skip to content

Commit 8746be8

Browse files
authored
Add benchmarks for MontyParams::new (#521)
The vartime constructor is 2.75X faster: Dynamic Montgomery arithmetic/MontyParams::new time: [5.8611 µs 5.8708 µs 5.8812 µs] Dynamic Montgomery arithmetic/MontyParams::new_vartime time: [2.1284 µs 2.1405 µs 2.1567 µs]
1 parent 3ce99d4 commit 8746be8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

benches/monty.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ use rand_core::OsRng;
1212
use crypto_bigint::MultiExponentiate;
1313

1414
fn bench_montgomery_conversion<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
15-
group.bench_function("MontyParams creation", |b| {
15+
group.bench_function("MontyParams::new", |b| {
16+
b.iter_batched(
17+
|| Odd::<U256>::random(&mut OsRng),
18+
|modulus| black_box(MontyParams::new(modulus)),
19+
BatchSize::SmallInput,
20+
)
21+
});
22+
23+
group.bench_function("MontyParams::new_vartime", |b| {
1624
b.iter_batched(
1725
|| Odd::<U256>::random(&mut OsRng),
1826
|modulus| black_box(MontyParams::new_vartime(modulus)),
@@ -21,7 +29,7 @@ fn bench_montgomery_conversion<M: Measurement>(group: &mut BenchmarkGroup<'_, M>
2129
});
2230

2331
let params = MontyParams::new_vartime(Odd::<U256>::random(&mut OsRng));
24-
group.bench_function("MontyForm creation", |b| {
32+
group.bench_function("MontyForm::new", |b| {
2533
b.iter_batched(
2634
|| Odd::<U256>::random(&mut OsRng),
2735
|x| black_box(MontyForm::new(&x, params)),

0 commit comments

Comments
 (0)