-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add benchmark for from_bytes() and from_bytes_unchecked() on Signatur…
…e and PublicKey in chia-bls
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,7 @@ harness = false | |
[[bench]] | ||
name = "verify" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "parse" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|