-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathencryption.rs
107 lines (100 loc) · 4.63 KB
/
encryption.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
use criterion::{
async_executor::AsyncStdExecutor as FuturesExecutor, black_box, criterion_group, criterion_main, BatchSize,
Criterion,
};
use rand::distributions::{Alphanumeric, DistString};
use crate::utils::*;
#[path = "utils/mod.rs"]
mod utils;
fn encryption_bench_var_group_size(c: &mut Criterion) {
let mut group = c.benchmark_group("Encrypt 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 (central, id, ..) =
setup_mls_and_add_clients(ciphersuite, credential.as_ref(), in_memory, *i).await;
let text = Alphanumeric.sample_string(&mut rand::thread_rng(), MSG_MAX);
(central, id, text)
})
},
|(central, id, text)| async move {
let context = central.new_transaction().await.unwrap();
black_box(context.encrypt_message(&id, text).await.unwrap());
context.finish().await.unwrap();
},
BatchSize::SmallInput,
)
});
}
}
group.finish();
}
fn encryption_bench_var_msg_size(c: &mut Criterion) {
let mut group = c.benchmark_group("Encrypt f(msg size)");
for (case, ciphersuite, credential, in_memory) in MlsTestCase::values() {
for i in (MSG_RANGE).step_by(MSG_STEP) {
group.bench_with_input(case.benchmark_id(i, in_memory), &i, |b, i| {
b.to_async(FuturesExecutor).iter_batched(
|| {
async_std::task::block_on(async {
let (central, id, ..) =
setup_mls_and_add_clients(ciphersuite, credential.as_ref(), in_memory, GROUP_MAX).await;
let text = Alphanumeric.sample_string(&mut rand::thread_rng(), *i);
(central, id, text)
})
},
|(central, id, text)| async move {
let context = central.new_transaction().await.unwrap();
black_box(context.encrypt_message(&id, text).await.unwrap());
context.finish().await.unwrap();
},
BatchSize::SmallInput,
)
});
}
}
group.finish();
}
fn decryption_bench_var_msg_size(c: &mut Criterion) {
let mut group = c.benchmark_group("Decrypt f(msg size)");
for (case, ciphersuite, credential, in_memory) in MlsTestCase::values() {
for i in (MSG_RANGE).step_by(MSG_STEP) {
group.bench_with_input(case.benchmark_id(i, in_memory), &i, |b, i| {
b.to_async(FuturesExecutor).iter_batched(
|| {
async_std::task::block_on(async {
let (mut alice_central, id, delivery_service) =
setup_mls(ciphersuite, credential.as_ref(), in_memory).await;
let (mut bob_central, ..) = new_central(ciphersuite, credential.as_ref(), in_memory).await;
invite(&mut alice_central, &mut bob_central, &id, ciphersuite, delivery_service).await;
let context = alice_central.new_transaction().await.unwrap();
let text = Alphanumeric.sample_string(&mut rand::thread_rng(), *i);
let encrypted = context.encrypt_message(&id, text).await.unwrap();
context.finish().await.unwrap();
(bob_central, id, encrypted)
})
},
|(central, id, encrypted)| async move {
let context = central.new_transaction().await.unwrap();
black_box(context.decrypt_message(&id, encrypted).await.unwrap());
context.finish().await.unwrap();
},
BatchSize::SmallInput,
)
});
}
}
group.finish();
}
criterion_group!(
name = encryption;
config = criterion();
targets =
encryption_bench_var_group_size,
encryption_bench_var_msg_size,
decryption_bench_var_msg_size,
);
criterion_main!(encryption);