-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcreate_group.rs
144 lines (136 loc) · 6.32 KB
/
create_group.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use criterion::{
async_executor::AsyncStdExecutor as FuturesExecutor, black_box, criterion_group, criterion_main, BatchSize,
BenchmarkId, Criterion,
};
use core_crypto::prelude::{MlsConversationConfiguration, MlsCredentialType, MlsCustomConfiguration};
use crate::utils::*;
#[path = "utils/mod.rs"]
mod utils;
/// Benchmark to measure the runtime of creating a group.
fn create_group_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("Create group");
for (case, ciphersuite, credential, in_memory) in MlsTestCase::values() {
group.bench_with_input(
BenchmarkId::from_parameter(case.ciphersuite_name(in_memory)),
&ciphersuite,
|b, ciphersuite| {
b.to_async(FuturesExecutor).iter_batched(
|| {
async_std::task::block_on(async {
let (central, ..) = new_central(*ciphersuite, credential.as_ref(), in_memory).await;
let id = conversation_id();
let cfg = MlsConversationConfiguration {
ciphersuite: *ciphersuite,
..Default::default()
};
(central, id, cfg)
})
},
|(central, id, cfg)| async move {
let context = central.new_transaction().await.unwrap();
context
.new_conversation(&id, MlsCredentialType::Basic, cfg)
.await
.unwrap();
context.finish().await.unwrap();
black_box(());
},
BatchSize::SmallInput,
)
},
);
}
group.finish();
}
/// Benchmark to measure the impact of group size on the runtime of joining a group from a welcome message.
fn join_from_welcome_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("Join from welcome f(group size)");
for (case, ciphersuite, credential, in_memory) in MlsTestCase::values() {
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 (alice_central, id, _, _, delivery_service) =
setup_mls_and_add_clients(ciphersuite, credential.as_ref(), in_memory, *i).await;
let (bob_central, ..) = new_central(ciphersuite, credential.as_ref(), in_memory).await;
let bob_context = bob_central.new_transaction().await.unwrap();
let bob_kpbs = bob_context
.get_or_create_client_keypackages(ciphersuite, MlsCredentialType::Basic, 1)
.await
.unwrap();
let bob_kp = bob_kpbs.first().unwrap().clone();
bob_context.finish().await.unwrap();
let alice_context = alice_central.new_transaction().await.unwrap();
alice_context
.add_members_to_conversation(&id, vec![bob_kp.into()])
.await
.unwrap();
let welcome = delivery_service.latest_welcome_message().await;
alice_context.finish().await.unwrap();
(bob_central, welcome)
})
},
|(central, welcome)| async move {
let context = central.new_transaction().await.unwrap();
black_box(
context
.process_welcome_message(welcome.into(), MlsCustomConfiguration::default())
.await
.unwrap(),
);
context.finish().await.unwrap();
},
BatchSize::SmallInput,
)
});
}
}
group.finish();
}
/// Benchmark to measure the impact of group size on the runtime of joining a group via an external commit.
fn join_from_group_info_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("Join from external commit f(group size)");
for (case, ciphersuite, credential, in_memory) in MlsTestCase::values() {
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 (_, _, _, group_info, ..) =
setup_mls_and_add_clients(ciphersuite, credential.as_ref(), in_memory, *i).await;
let (bob_central, ..) = new_central(ciphersuite, credential.as_ref(), in_memory).await;
(bob_central, group_info)
})
},
|(central, group_info)| async move {
let context = central.new_transaction().await.unwrap();
black_box(
context
.join_by_external_commit(
group_info,
MlsCustomConfiguration::default(),
MlsCredentialType::Basic,
)
.await
.unwrap(),
);
context.finish().await.unwrap();
black_box(());
},
BatchSize::SmallInput,
)
});
}
}
group.finish();
}
criterion_group!(
name = create_group;
config = criterion();
targets =
create_group_bench,
join_from_welcome_bench,
join_from_group_info_bench,
);
criterion_main!(create_group);