From 27a61a28cca0d156242110908c96258be90b9265 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 27 Dec 2023 11:35:50 -0700 Subject: [PATCH] Add benchmarks for `MontyParams::new` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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] --- benches/monty.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/benches/monty.rs b/benches/monty.rs index 7141951b0..984af6aee 100644 --- a/benches/monty.rs +++ b/benches/monty.rs @@ -12,7 +12,15 @@ use rand_core::OsRng; use crypto_bigint::MultiExponentiate; fn bench_montgomery_conversion(group: &mut BenchmarkGroup<'_, M>) { - group.bench_function("MontyParams creation", |b| { + group.bench_function("MontyParams::new", |b| { + b.iter_batched( + || Odd::::random(&mut OsRng), + |modulus| black_box(MontyParams::new(modulus)), + BatchSize::SmallInput, + ) + }); + + group.bench_function("MontyParams::new_vartime", |b| { b.iter_batched( || Odd::::random(&mut OsRng), |modulus| black_box(MontyParams::new_vartime(modulus)), @@ -21,7 +29,7 @@ fn bench_montgomery_conversion(group: &mut BenchmarkGroup<'_, M> }); let params = MontyParams::new_vartime(Odd::::random(&mut OsRng)); - group.bench_function("MontyForm creation", |b| { + group.bench_function("MontyForm::new", |b| { b.iter_batched( || Odd::::random(&mut OsRng), |x| black_box(MontyForm::new(&x, params)),