Regroup the benchmarks by input size

This commit is contained in:
Rodolphe Bréard 2024-06-22 12:47:10 +02:00
parent 682a9d579b
commit 0955da7e09
3 changed files with 37 additions and 34 deletions

View file

@ -25,32 +25,30 @@ pub const PLAIN_INPUTS: &[(&str, &str)] = &[
("04 - 3 KB", include_str!("data/plain_04_l.txt")),
("05 - 1 MB", include_str!("data/plain_05_xl.txt")),
];
pub const AES128GCM_SHA256_INPUTS: &[(&str, &str)] = &[
("01 - 12 B", include_str!("data/aes128gcm-sha256_01_xs.txt")),
("02 - 60 B", include_str!("data/aes128gcm-sha256_02_s.txt")),
("03 - 500 B", include_str!("data/aes128gcm-sha256_03_m.txt")),
("04 - 3 KB", include_str!("data/aes128gcm-sha256_04_l.txt")),
("05 - 1 MB", include_str!("data/aes128gcm-sha256_05_xl.txt")),
];
pub const XCHACHA20POLY1305_BLAKE3_INPUTS: &[(&str, &str)] = &[
pub const ENCRYPTED_INPUTS: &[(&str, &str, &str)] = &[
(
"01 - 12 B",
include_str!("data/aes128gcm-sha256_01_xs.txt"),
include_str!("data/xchacha20poly1305-blake3_01_xs.txt"),
),
(
"02 - 60 B",
include_str!("data/aes128gcm-sha256_02_s.txt"),
include_str!("data/xchacha20poly1305-blake3_02_s.txt"),
),
(
"03 - 500 B",
include_str!("data/aes128gcm-sha256_03_m.txt"),
include_str!("data/xchacha20poly1305-blake3_03_m.txt"),
),
(
"04 - 3 KB",
include_str!("data/aes128gcm-sha256_04_l.txt"),
include_str!("data/xchacha20poly1305-blake3_04_l.txt"),
),
(
"05 - 1 MB",
include_str!("data/aes128gcm-sha256_05_xl.txt"),
include_str!("data/xchacha20poly1305-blake3_05_xl.txt"),
),
];

View file

@ -3,19 +3,14 @@ mod data;
use coffio::{Coffio, DataContext, InputKeyMaterialList, KeyContext};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use data::{
Data, AES128GCM_SHA256_INPUTS, DATA_CTX, IKML_AES128GCM_SHA256, IKML_XCHACHA20POLY1305_BLAKE3,
KEY_CTX, MEASUREMENT_TIME, XCHACHA20POLY1305_BLAKE3_INPUTS,
Data, DATA_CTX, ENCRYPTED_INPUTS, IKML_AES128GCM_SHA256, IKML_XCHACHA20POLY1305_BLAKE3,
KEY_CTX, MEASUREMENT_TIME,
};
use std::time::Duration;
macro_rules! alg_group {
($group: ident, $name: expr, $inputs: ident, $ikml: ident) => {
for (input_name, input) in $inputs.iter() {
let data = Data { ikml: $ikml, input };
$group.bench_with_input(BenchmarkId::new($name, input_name), &data, |b, i| {
b.iter(|| decrypt_coffio(i.ikml, i.input))
});
}
for (input_name, input) in $inputs.iter() {}
};
}
@ -30,20 +25,30 @@ fn decrypt_coffio(ikml: &str, input: &str) {
}
pub fn decryption_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Decryption");
group.measurement_time(Duration::from_secs(MEASUREMENT_TIME));
alg_group!(
group,
"Aes128GcmWithSha256",
AES128GCM_SHA256_INPUTS,
IKML_AES128GCM_SHA256
);
alg_group!(
group,
"XChaCha20Poly1305WithBlake3",
XCHACHA20POLY1305_BLAKE3_INPUTS,
IKML_XCHACHA20POLY1305_BLAKE3
);
for (name, input_aes, input_xchacha) in ENCRYPTED_INPUTS {
let mut group = c.benchmark_group(format!("Decryption {name}"));
group.measurement_time(Duration::from_secs(MEASUREMENT_TIME));
let data = Data {
ikml: IKML_AES128GCM_SHA256,
input: input_aes,
};
group.bench_with_input(
BenchmarkId::new("Aes128GcmWithSha256", name),
&data,
|b, i| b.iter(|| decrypt_coffio(i.ikml, i.input)),
);
let data = Data {
ikml: IKML_XCHACHA20POLY1305_BLAKE3,
input: input_xchacha,
};
group.bench_with_input(
BenchmarkId::new("XChaCha20Poly1305WithBlake3", name),
&data,
|b, i| b.iter(|| decrypt_coffio(i.ikml, i.input)),
);
}
}
criterion_group!(benches, decryption_benchmark);

View file

@ -16,10 +16,10 @@ fn encrypt_coffio(ikml: &str, input: &str) {
}
pub fn encryption_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Encryption");
group.measurement_time(Duration::from_secs(MEASUREMENT_TIME));
for (alg_name, ikml) in IKMLS.iter() {
for (input_name, input) in PLAIN_INPUTS.iter() {
for (input_name, input) in PLAIN_INPUTS.iter() {
let mut group = c.benchmark_group(format!("Encryption {input_name}"));
group.measurement_time(Duration::from_secs(MEASUREMENT_TIME));
for (alg_name, ikml) in IKMLS.iter() {
let data = Data { ikml, input };
group.bench_with_input(BenchmarkId::new(*alg_name, input_name), &data, |b, i| {
b.iter(|| encrypt_coffio(i.ikml, i.input))