-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathkey_package.rs
89 lines (83 loc) · 3.4 KB
/
key_package.rs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use core_crypto::prelude::MlsCredentialType;
use criterion::{
async_executor::AsyncStdExecutor as FuturesExecutor, black_box, criterion_group, criterion_main, BatchSize,
Criterion,
};
use crate::utils::*;
#[path = "utils/mod.rs"]
mod utils;
fn generate_key_package_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("Generate KeyPackage f(group size)");
for (case, ciphersuite, credential, in_memory) in MlsTestCase::values() {
let credential_type = credential
.as_ref()
.map(|_| MlsCredentialType::X509)
.unwrap_or(MlsCredentialType::Basic);
for i in (GROUP_RANGE).step_by(GROUP_STEP) {
group.bench_with_input(case.benchmark_id(i + 1, in_memory), &i, |b, i| {
b.to_async(FuturesExecutor).iter_batched(
|| async_std::task::block_on(setup_mls(ciphersuite, credential.as_ref(), in_memory)),
|(central, _, _)| async move {
let context = central.new_transaction().await.unwrap();
black_box(
context
.get_or_create_client_keypackages(ciphersuite, credential_type, *i)
.await
.unwrap(),
);
context.finish().await.unwrap();
},
BatchSize::SmallInput,
)
});
}
}
group.finish();
}
fn count_key_packages_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("Count KeyPackage");
for (case, ciphersuite, credential, in_memory) in MlsTestCase::values() {
let credential_type = credential
.as_ref()
.map(|_| MlsCredentialType::X509)
.unwrap_or(MlsCredentialType::Basic);
for i in (GROUP_RANGE).step_by(GROUP_STEP) {
group.bench_with_input(case.benchmark_id(i + 1, in_memory), &i, |b, i| {
b.to_async(FuturesExecutor).iter_batched(
|| {
async_std::task::block_on(async {
let (central, ..) = setup_mls(ciphersuite, credential.as_ref(), in_memory).await;
let context = central.new_transaction().await.unwrap();
context
.get_or_create_client_keypackages(ciphersuite, credential_type, *i)
.await
.unwrap();
context.finish().await.unwrap();
central
})
},
|central| async move {
let context = central.new_transaction().await.unwrap();
black_box(
context
.client_valid_key_packages_count(ciphersuite, credential_type)
.await
.unwrap(),
);
context.finish().await.unwrap();
},
BatchSize::SmallInput,
)
});
}
}
group.finish();
}
criterion_group!(
name = key_package;
config = criterion();
targets =
generate_key_package_bench,
count_key_packages_bench,
);
criterion_main!(key_package);