mirror of
https://github.com/RustCrypto/signatures
synced 2026-06-21 13:45:42 +00:00
ecdsa: add bench_ecdsa! macro (#1142)
Adds a macro for writing `criterion` benchmarks for ECDSA signing and verification, similar to other benchmark macros recently added to `elliptic-curve` and `primeorder`. The macro should be compatible with both `criterion` v0.7 and v0.8, allowing for downstream users to ship with MSRV 1.85 support then upgrade later without requiring breaking changes to this macro.
This commit is contained in:
@@ -8,6 +8,44 @@ pub use digest::dev::blobby;
|
||||
use crate::EcdsaCurve;
|
||||
use elliptic_curve::dev::mock_curve::MockCurve;
|
||||
|
||||
/// Write a series of `criterion`-based benchmarks for ECDSA signing and verification.
|
||||
#[macro_export]
|
||||
macro_rules! bench_ecdsa {
|
||||
($name:ident, $desc:expr, $signing_key:expr, $signature:ty) => {
|
||||
fn bench_sign<M: ::criterion::measurement::Measurement>(
|
||||
group: &mut ::criterion::BenchmarkGroup<'_, M>,
|
||||
) {
|
||||
use $crate::signature::Signer as _;
|
||||
let sk = core::hint::black_box($signing_key);
|
||||
let msg = core::hint::black_box(b"example message");
|
||||
group.bench_function("sign", |b| {
|
||||
b.iter(|| {
|
||||
let sig: Signature = sk.sign(msg);
|
||||
core::hint::black_box(sig)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_verify<M: ::criterion::measurement::Measurement>(
|
||||
group: &mut ::criterion::BenchmarkGroup<'_, M>,
|
||||
) {
|
||||
use $crate::signature::{Signer as _, Verifier as _};
|
||||
let sk = $signing_key;
|
||||
let vk = sk.verifying_key();
|
||||
let msg = core::hint::black_box(b"example message");
|
||||
let sig: Signature = core::hint::black_box(sk.sign(msg));
|
||||
group.bench_function("verify", |b| b.iter(|| vk.verify(msg, &sig)));
|
||||
}
|
||||
|
||||
fn $name(c: &mut ::criterion::Criterion) {
|
||||
let mut group = c.benchmark_group($desc);
|
||||
bench_sign(&mut group);
|
||||
bench_verify(&mut group);
|
||||
group.finish();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Define ECDSA signing test.
|
||||
#[macro_export]
|
||||
macro_rules! new_signing_test {
|
||||
|
||||
Reference in New Issue
Block a user