-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench.rs
More file actions
55 lines (44 loc) · 1.54 KB
/
Copy pathbench.rs
File metadata and controls
55 lines (44 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use criterion::{criterion_group, criterion_main, Criterion};
use ibs::{
gg,
gg::{Identity, Signer, Verifier},
};
use std::hint::black_box;
use rand::prelude::*;
pub fn criterion_benchmark_ibs(c: &mut Criterion) {
let mut rng = rand::rng();
let (pk, sk) = gg::setup(&mut rng);
let id = Identity::from("Johny");
let usk_id = gg::keygen(&sk, &id, &mut rng);
let sig = Signer::new().chain(b"Some message").sign(&usk_id, &mut rng);
c.bench_function("setup", |b| b.iter(|| gg::setup(&mut rng)));
c.bench_function("keygen", |b| {
b.iter(|| gg::keygen(black_box(&sk), black_box(&id), &mut rng))
});
let mut group = c.benchmark_group("GG sign/verify");
group.sample_size(10);
for l in (10..22).step_by(2) {
let size: u64 = 2u64.pow(l);
group.throughput(criterion::Throughput::Bytes(size));
let mut msg = vec![0u8; size as usize];
rng.fill_bytes(&mut msg);
group.bench_function(format!("sign {size}"), |b| {
b.iter(|| {
Signer::new()
.chain(black_box(&msg))
.sign(black_box(&usk_id), &mut rng)
})
});
group.bench_function(format!("verify {size}"), |b| {
b.iter(|| {
Verifier::new().chain(black_box(&msg)).verify(
black_box(&pk),
black_box(&sig),
black_box(&id),
)
})
});
}
}
criterion_group!(benches, criterion_benchmark_ibs);
criterion_main!(benches);