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")), ("04 - 3 KB", include_str!("data/plain_04_l.txt")),
("05 - 1 MB", include_str!("data/plain_05_xl.txt")), ("05 - 1 MB", include_str!("data/plain_05_xl.txt")),
]; ];
pub const AES128GCM_SHA256_INPUTS: &[(&str, &str)] = &[ pub const ENCRYPTED_INPUTS: &[(&str, &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)] = &[
( (
"01 - 12 B", "01 - 12 B",
include_str!("data/aes128gcm-sha256_01_xs.txt"),
include_str!("data/xchacha20poly1305-blake3_01_xs.txt"), include_str!("data/xchacha20poly1305-blake3_01_xs.txt"),
), ),
( (
"02 - 60 B", "02 - 60 B",
include_str!("data/aes128gcm-sha256_02_s.txt"),
include_str!("data/xchacha20poly1305-blake3_02_s.txt"), include_str!("data/xchacha20poly1305-blake3_02_s.txt"),
), ),
( (
"03 - 500 B", "03 - 500 B",
include_str!("data/aes128gcm-sha256_03_m.txt"),
include_str!("data/xchacha20poly1305-blake3_03_m.txt"), include_str!("data/xchacha20poly1305-blake3_03_m.txt"),
), ),
( (
"04 - 3 KB", "04 - 3 KB",
include_str!("data/aes128gcm-sha256_04_l.txt"),
include_str!("data/xchacha20poly1305-blake3_04_l.txt"), include_str!("data/xchacha20poly1305-blake3_04_l.txt"),
), ),
( (
"05 - 1 MB", "05 - 1 MB",
include_str!("data/aes128gcm-sha256_05_xl.txt"),
include_str!("data/xchacha20poly1305-blake3_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 coffio::{Coffio, DataContext, InputKeyMaterialList, KeyContext};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use data::{ use data::{
Data, AES128GCM_SHA256_INPUTS, DATA_CTX, IKML_AES128GCM_SHA256, IKML_XCHACHA20POLY1305_BLAKE3, Data, DATA_CTX, ENCRYPTED_INPUTS, IKML_AES128GCM_SHA256, IKML_XCHACHA20POLY1305_BLAKE3,
KEY_CTX, MEASUREMENT_TIME, XCHACHA20POLY1305_BLAKE3_INPUTS, KEY_CTX, MEASUREMENT_TIME,
}; };
use std::time::Duration; use std::time::Duration;
macro_rules! alg_group { macro_rules! alg_group {
($group: ident, $name: expr, $inputs: ident, $ikml: ident) => { ($group: ident, $name: expr, $inputs: ident, $ikml: ident) => {
for (input_name, input) in $inputs.iter() { 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))
});
}
}; };
} }
@ -30,20 +25,30 @@ fn decrypt_coffio(ikml: &str, input: &str) {
} }
pub fn decryption_benchmark(c: &mut Criterion) { pub fn decryption_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Decryption"); for (name, input_aes, input_xchacha) in ENCRYPTED_INPUTS {
group.measurement_time(Duration::from_secs(MEASUREMENT_TIME)); let mut group = c.benchmark_group(format!("Decryption {name}"));
alg_group!( group.measurement_time(Duration::from_secs(MEASUREMENT_TIME));
group,
"Aes128GcmWithSha256", let data = Data {
AES128GCM_SHA256_INPUTS, ikml: IKML_AES128GCM_SHA256,
IKML_AES128GCM_SHA256 input: input_aes,
); };
alg_group!( group.bench_with_input(
group, BenchmarkId::new("Aes128GcmWithSha256", name),
"XChaCha20Poly1305WithBlake3", &data,
XCHACHA20POLY1305_BLAKE3_INPUTS, |b, i| b.iter(|| decrypt_coffio(i.ikml, i.input)),
IKML_XCHACHA20POLY1305_BLAKE3 );
);
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); 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) { pub fn encryption_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Encryption"); for (input_name, input) in PLAIN_INPUTS.iter() {
group.measurement_time(Duration::from_secs(MEASUREMENT_TIME)); let mut group = c.benchmark_group(format!("Encryption {input_name}"));
for (alg_name, ikml) in IKMLS.iter() { group.measurement_time(Duration::from_secs(MEASUREMENT_TIME));
for (input_name, input) in PLAIN_INPUTS.iter() { for (alg_name, ikml) in IKMLS.iter() {
let data = Data { ikml, input }; let data = Data { ikml, input };
group.bench_with_input(BenchmarkId::new(*alg_name, input_name), &data, |b, i| { group.bench_with_input(BenchmarkId::new(*alg_name, input_name), &data, |b, i| {
b.iter(|| encrypt_coffio(i.ikml, i.input)) b.iter(|| encrypt_coffio(i.ikml, i.input))