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;
7 use mls_rs::CipherSuite;
8 use rand::RngCore;
9
bench(c: &mut Criterion)10 fn bench(c: &mut Criterion) {
11 let cipher_suite = CipherSuite::CURVE25519_AES128;
12 let group_states = load_group_states(cipher_suite).pop().unwrap();
13
14 let mut bytes = vec![0; 1000000];
15 rand::thread_rng().fill_bytes(&mut bytes);
16
17 let bytes = &bytes;
18 let mut n = 100;
19 let mut bench_group = c.benchmark_group("group_application");
20
21 while n <= 1000000 {
22 bench_group.throughput(Throughput::Bytes(n as u64));
23 bench_group.bench_with_input(
24 BenchmarkId::new(format!("{cipher_suite:?}"), n),
25 &n,
26 |b, _| {
27 b.iter_batched_ref(
28 || group_states.clone(),
29 move |group_states| {
30 let msg = group_states
31 .sender
32 .encrypt_application_message(&bytes[..n], vec![])
33 .unwrap();
34
35 group_states.receiver.process_incoming_message(msg).unwrap();
36 },
37 BatchSize::SmallInput,
38 )
39 },
40 );
41
42 n *= 10;
43 }
44 bench_group.finish();
45 }
46
47 criterion::criterion_group!(benches, bench);
48 criterion::criterion_main!(benches);
49