From 5fd462a110a56779cf3a650a8b2387404c16ebb3 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Tue, 18 Oct 2022 18:59:41 -0700 Subject: [PATCH] Add Additional benchmarks and buffer size Signed-off-by: Joe Richey --- benches/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/benches/mod.rs b/benches/mod.rs index 07474b66..9a8f080e 100644 --- a/benches/mod.rs +++ b/benches/mod.rs @@ -7,6 +7,7 @@ use std::mem::MaybeUninit; // The buffer is hot, and does not require initialization. #[inline(always)] fn bench_getrandom(b: &mut test::Bencher) { + b.bytes = N as u64; b.iter(|| { let mut buf = [0u8; N]; getrandom::getrandom(&mut buf[..]).unwrap(); @@ -18,6 +19,7 @@ fn bench_getrandom(b: &mut test::Bencher) { // scenario. The buffer is still hot, but requires initialization. #[inline(always)] fn bench_getrandom_uninit(b: &mut test::Bencher) { + b.bytes = N as u64; b.iter(|| { // TODO: When the feature `maybe_uninit_as_bytes` is available, use: // ``` @@ -48,6 +50,9 @@ macro_rules! bench { }; } +// 16 bytes (128 bits) is the size of an 128-bit AES key/nonce. +bench!(aes128, 128 / 8); + // 32 bytes (256 bits) is the seed sized used for rand::thread_rng // and the `random` value in a ClientHello/ServerHello for TLS. // This is also the size of a 256-bit AES/HMAC/P-256/Curve25519 key @@ -56,3 +61,8 @@ bench!(p256, 256 / 8); // A P-384/HMAC-384 key and/or nonce. bench!(p384, 384 / 8); + +// Initializing larger buffers is not the primary use case of this library, as +// this should normally be done by a userspace CSPRNG. However, we have a test +// here to see the effects of a lower (amortized) syscall overhead. +bench!(page, 4096);