Skip to content

Commit

Permalink
Benchmarks: Consume the result in black_box.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Oct 20, 2022
1 parent 121b169 commit 8bf7c8d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions benches/mod.rs
Expand Up @@ -13,7 +13,7 @@ fn bench_getrandom<const N: usize>(b: &mut test::Bencher) {
b.iter(|| {
let mut buf = [0u8; N];
getrandom::getrandom(&mut buf[..]).unwrap();
test::black_box(&buf);
test::black_box(buf);
});
}

Expand All @@ -26,8 +26,9 @@ fn bench_getrandom_uninit<const N: usize>(b: &mut test::Bencher) {
// TODO: When the feature `maybe_uninit_as_bytes` is available, use:
// since that is the shape we expect most callers to have.
let mut buf: MaybeUninit<[u8; N]> = MaybeUninit::uninit();
let buf = getrandom::getrandom_uninit(buf.as_bytes_mut()).unwrap();
test::black_box(buf);
let _ = getrandom::getrandom_uninit(buf.as_bytes_mut()).unwrap();
let buf: [u8; N] = unsafe { buf.assume_init() };
test::black_box(buf)
});
}

Expand Down

0 comments on commit 8bf7c8d

Please sign in to comment.