bls: uncompressed serialization

This commit is contained in:
Michael Sproul
2022-10-20 16:35:51 +11:00
parent 3f71de8c2d
commit 03fde98737
10 changed files with 164 additions and 16 deletions

View File

@@ -0,0 +1,64 @@
use bls::{PublicKey, SecretKey};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
pub fn compress(c: &mut Criterion) {
let private_key = SecretKey::random();
let public_key = private_key.public_key();
c.bench_with_input(
BenchmarkId::new("compress", 1),
&public_key,
|b, public_key| {
b.iter(|| public_key.compress());
},
);
}
pub fn decompress(c: &mut Criterion) {
let private_key = SecretKey::random();
let public_key_bytes = private_key.public_key().compress();
c.bench_with_input(
BenchmarkId::new("decompress", 1),
&public_key_bytes,
|b, public_key_bytes| {
b.iter(|| public_key_bytes.decompress().unwrap());
},
);
}
pub fn deserialize_uncompressed(c: &mut Criterion) {
let private_key = SecretKey::random();
let public_key_bytes = private_key.public_key().serialize_uncompressed();
c.bench_with_input(
BenchmarkId::new("deserialize_uncompressed", 1),
&public_key_bytes,
|b, public_key_bytes| {
b.iter(|| PublicKey::deserialize_uncompressed(public_key_bytes).unwrap());
},
);
}
pub fn compress_all(c: &mut Criterion) {
let n = 500_000;
let keys = (0..n)
.map(|_| {
let private_key = SecretKey::random();
private_key.public_key()
})
.collect::<Vec<_>>();
c.bench_with_input(BenchmarkId::new("compress", n), &keys, |b, keys| {
b.iter(|| {
for key in keys {
key.compress();
}
});
});
}
criterion_group!(
benches,
compress,
decompress,
deserialize_uncompressed,
compress_all
);
criterion_main!(benches);