Skip to content

Commit 5fd462a

Browse files
committed
Add Additional benchmarks and buffer size
Signed-off-by: Joe Richey <joerichey@google.com>
1 parent b797731 commit 5fd462a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

benches/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::mem::MaybeUninit;
77
// The buffer is hot, and does not require initialization.
88
#[inline(always)]
99
fn bench_getrandom<const N: usize>(b: &mut test::Bencher) {
10+
b.bytes = N as u64;
1011
b.iter(|| {
1112
let mut buf = [0u8; N];
1213
getrandom::getrandom(&mut buf[..]).unwrap();
@@ -18,6 +19,7 @@ fn bench_getrandom<const N: usize>(b: &mut test::Bencher) {
1819
// scenario. The buffer is still hot, but requires initialization.
1920
#[inline(always)]
2021
fn bench_getrandom_uninit<const N: usize>(b: &mut test::Bencher) {
22+
b.bytes = N as u64;
2123
b.iter(|| {
2224
// TODO: When the feature `maybe_uninit_as_bytes` is available, use:
2325
// ```
@@ -48,6 +50,9 @@ macro_rules! bench {
4850
};
4951
}
5052

53+
// 16 bytes (128 bits) is the size of an 128-bit AES key/nonce.
54+
bench!(aes128, 128 / 8);
55+
5156
// 32 bytes (256 bits) is the seed sized used for rand::thread_rng
5257
// and the `random` value in a ClientHello/ServerHello for TLS.
5358
// This is also the size of a 256-bit AES/HMAC/P-256/Curve25519 key
@@ -56,3 +61,8 @@ bench!(p256, 256 / 8);
5661

5762
// A P-384/HMAC-384 key and/or nonce.
5863
bench!(p384, 384 / 8);
64+
65+
// Initializing larger buffers is not the primary use case of this library, as
66+
// this should normally be done by a userspace CSPRNG. However, we have a test
67+
// here to see the effects of a lower (amortized) syscall overhead.
68+
bench!(page, 4096);

0 commit comments

Comments
 (0)