From 0955da7e095a14c8063fdbb8ff93a81dd70c6f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sat, 22 Jun 2024 12:47:10 +0200 Subject: [PATCH] Regroup the benchmarks by input size --- benches/data.rs | 14 ++++++------- benches/decryption.rs | 49 ++++++++++++++++++++++++------------------- benches/encryption.rs | 8 +++---- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/benches/data.rs b/benches/data.rs index ad5f73c..62ccee3 100644 --- a/benches/data.rs +++ b/benches/data.rs @@ -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"), ), ]; diff --git a/benches/decryption.rs b/benches/decryption.rs index 203f1a7..f5744d8 100644 --- a/benches/decryption.rs +++ b/benches/decryption.rs @@ -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); diff --git a/benches/encryption.rs b/benches/encryption.rs index ea9d0e0..3641b5f 100644 --- a/benches/encryption.rs +++ b/benches/encryption.rs @@ -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))