Skip to content

Commit ff87698

Browse files
committed
Add benchmarks for Scalar::from_canonical_bytes
1 parent 06186b8 commit ff87698

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

benches/dalek_benchmarks.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(non_snake_case)]
22

33
use rand::rngs::OsRng;
4-
use rand::thread_rng;
4+
use rand::{thread_rng, Rng};
55

66
use criterion::measurement::Measurement;
77
use criterion::BatchSize;
@@ -47,6 +47,25 @@ mod edwards_benches {
4747
});
4848
}
4949

50+
fn scalar_from_canonical_bytes(c: &mut Criterion) {
51+
let bytes = [0xFF; 32];
52+
c.bench_function("Max scalar from_canonical_bytes", move |b| {
53+
b.iter(|| Scalar::from_canonical_bytes(bytes))
54+
});
55+
let bytes = [0u8; 32];
56+
c.bench_function("Zero scalar from_canonical_bytes", move |b| {
57+
b.iter(|| Scalar::from_canonical_bytes(bytes))
58+
});
59+
c.bench_function("Rand scalar from_canonical_bytes", |bench| {
60+
let mut rng = thread_rng();
61+
bench.iter_batched(
62+
|| rng.gen(),
63+
|bytes| Scalar::from_canonical_bytes(bytes),
64+
BatchSize::SmallInput,
65+
);
66+
});
67+
}
68+
5069
fn vartime_double_base_scalar_mul(c: &mut Criterion) {
5170
c.bench_function("Variable-time aA+bB, A variable, B fixed", |bench| {
5271
let mut rng = thread_rng();
@@ -68,6 +87,7 @@ mod edwards_benches {
6887
consttime_fixed_base_scalar_mul,
6988
consttime_variable_base_scalar_mul,
7089
vartime_double_base_scalar_mul,
90+
scalar_from_canonical_bytes,
7191
}
7292
}
7393

0 commit comments

Comments
 (0)