Debian Codegraph @

third_party/rust/mls-rs/benches/group_application.rs

raw
1 // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 // Copyright by contributors to this project.
3 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
4
5 use criterion::{BatchSize, BenchmarkId, Criterion, Throughput};
6 use mls_rs::test_utils::benchmarks::{load_group_states, BENCH_CIPHER_SUITE};
7 use rand::RngCore;
8
9 fn bench(c: &mut Criterion) {
10 let group_states = load_group_states().pop().unwrap();
11
12 let mut bytes = vec![0; 1000000];
13 rand::thread_rng().fill_bytes(&mut bytes);
14
15 let bytes = &bytes;
16 let mut n = 100;
17 let mut bench_group = c.benchmark_group("group_application");
18
19 while n <= 1000000 {
20 bench_group.throughput(Throughput::Bytes(n as u64));
21 bench_group.bench_with_input(
22 BenchmarkId::new(format!("{BENCH_CIPHER_SUITE:?}"), n),
23 &n,
24 |b, _| {
25 b.iter_batched_ref(
26 || group_states.clone(),
27 move |group_states| {
28 let msg = group_states
29 .sender
30 .encrypt_application_message(&bytes[..n], vec![])
31 .unwrap();
32
33 group_states.receiver.process_incoming_message(msg).unwrap();
34 },
35 BatchSize::SmallInput,
36 )
37 },
38 );
39
40 n *= 10;
41 }
42 bench_group.finish();
43 }
44
45 criterion::criterion_group!(benches, bench);
46 criterion::criterion_main!(benches);