Skip to content

Commit

Permalink
Avoid initializing the buffer in getrandom_uninit benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Oct 20, 2022
1 parent 47d5dcc commit 121b169
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions benches/mod.rs
@@ -1,4 +1,6 @@
#![feature(test)]
#![feature(maybe_uninit_as_bytes)]

extern crate test;

use std::mem::MaybeUninit;
Expand All @@ -22,15 +24,10 @@ 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:
// ```
// let mut buf: MaybeUninit<[u8; N]> = MaybeUninit::uninit();
// getrandom::getrandom_uninit(buf.as_bytes_mut()).unwrap();
// test::black_box(unsafe { buf.assume_init() })
// ```
// since that is the shape we expect most callers to have.
let mut buf = [MaybeUninit::new(0u8); N];
let buf = getrandom::getrandom_uninit(&mut buf[..]).unwrap();
test::black_box(&buf);
let mut buf: MaybeUninit<[u8; N]> = MaybeUninit::uninit();
let buf = getrandom::getrandom_uninit(buf.as_bytes_mut()).unwrap();
test::black_box(buf);
});
}

Expand Down

0 comments on commit 121b169

Please sign in to comment.