Skip to content

Commit

Permalink
add benchmark for from_bytes() and from_bytes_unchecked() on Signatur…
Browse files Browse the repository at this point in the history
…e and PublicKey in chia-bls
  • Loading branch information
arvidn committed Nov 25, 2023
1 parent 9dfeff7 commit ed99f01
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chia-bls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ harness = false
[[bench]]
name = "verify"
harness = false

[[bench]]
name = "parse"
harness = false
49 changes: 49 additions & 0 deletions chia-bls/benches/parse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use chia_bls::secret_key::SecretKey;
use chia_bls::signature::sign;
use chia_bls::Signature;
use chia_bls::PublicKey;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};

fn parse_benchmark(c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(1337);
let mut data = [0u8; 32];
rng.fill(data.as_mut_slice());

let sk = SecretKey::from_seed(&data);
let pk = sk.public_key();
let msg = b"The quick brown fox jumps over the lazy dog";
let sig = sign(&sk, msg);

let sig_bytes = sig.to_bytes();
let pk_bytes = pk.to_bytes();

c.bench_function("parse Signature", |b| {
b.iter(|| {
let _ = black_box(Signature::from_bytes(&sig_bytes));
});
});

c.bench_function("parse PublicKey", |b| {
b.iter(|| {
let _ = black_box(PublicKey::from_bytes(&pk_bytes));
});
});

c.bench_function("parse Signature (unchecked)", |b| {
b.iter(|| {
let _ = black_box(Signature::from_bytes_unchecked(&sig_bytes));
});
});

c.bench_function("parse PublicKey (unchecked)", |b| {
b.iter(|| {
let _ = black_box(PublicKey::from_bytes_unchecked(&pk_bytes));
});
});
}

criterion_group!(parse, parse_benchmark);
criterion_main!(parse);

0 comments on commit ed99f01

Please sign in to comment.