Skip to content

Commit

Permalink
Add Additional benchmarks and buffer size
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Richey <joerichey@google.com>
  • Loading branch information
josephlr committed Oct 19, 2022
1 parent b797731 commit 5fd462a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions benches/mod.rs
Expand Up @@ -7,6 +7,7 @@ use std::mem::MaybeUninit;
// The buffer is hot, and does not require initialization.
#[inline(always)]
fn bench_getrandom<const N: usize>(b: &mut test::Bencher) {
b.bytes = N as u64;
b.iter(|| {
let mut buf = [0u8; N];
getrandom::getrandom(&mut buf[..]).unwrap();
Expand All @@ -18,6 +19,7 @@ fn bench_getrandom<const N: usize>(b: &mut test::Bencher) {
// scenario. The buffer is still hot, but requires initialization.
#[inline(always)]
fn bench_getrandom_uninit<const N: usize>(b: &mut test::Bencher) {
b.bytes = N as u64;
b.iter(|| {
// TODO: When the feature `maybe_uninit_as_bytes` is available, use:
// ```
Expand Down Expand Up @@ -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
Expand All @@ -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);

0 comments on commit 5fd462a

Please sign in to comment.