From 1b6a04ca5504955c571d1c97504fb45ea0befee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 8 Jan 2024 01:21:28 +0400 Subject: Initial vendor packages Signed-off-by: Valentin Popov --- vendor/fastrand/benches/bench.rs | 98 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 vendor/fastrand/benches/bench.rs (limited to 'vendor/fastrand/benches/bench.rs') diff --git a/vendor/fastrand/benches/bench.rs b/vendor/fastrand/benches/bench.rs new file mode 100644 index 0000000..a940aac --- /dev/null +++ b/vendor/fastrand/benches/bench.rs @@ -0,0 +1,98 @@ +#![feature(test)] + +extern crate test; + +use rand::prelude::*; +use test::Bencher; +use wyhash::WyRng; + +#[bench] +fn shuffle_wyhash(b: &mut Bencher) { + let mut rng = WyRng::from_rng(thread_rng()).unwrap(); + let mut x = (0..100).collect::>(); + b.iter(|| { + x.shuffle(&mut rng); + x[0] + }) +} + +#[bench] +fn shuffle_fastrand(b: &mut Bencher) { + let mut rng = fastrand::Rng::new(); + let mut x = (0..100).collect::>(); + b.iter(|| { + rng.shuffle(&mut x); + x[0] + }) +} + +#[bench] +fn u8_wyhash(b: &mut Bencher) { + let mut rng = WyRng::from_rng(thread_rng()).unwrap(); + b.iter(|| { + let mut sum = 0u8; + for _ in 0..10_000 { + sum = sum.wrapping_add(rng.gen::()); + } + sum + }) +} + +#[bench] +fn u8_fastrand(b: &mut Bencher) { + let mut rng = fastrand::Rng::new(); + b.iter(|| { + let mut sum = 0u8; + for _ in 0..10_000 { + sum = sum.wrapping_add(rng.u8(..)); + } + sum + }) +} + +#[bench] +fn u32_wyhash(b: &mut Bencher) { + let mut rng = WyRng::from_rng(thread_rng()).unwrap(); + b.iter(|| { + let mut sum = 0u32; + for _ in 0..10_000 { + sum = sum.wrapping_add(rng.gen::()); + } + sum + }) +} + +#[bench] +fn u32_fastrand(b: &mut Bencher) { + let mut rng = fastrand::Rng::new(); + b.iter(|| { + let mut sum = 0u32; + for _ in 0..10_000 { + sum = sum.wrapping_add(rng.u32(..)); + } + sum + }) +} + +#[bench] +fn fill(b: &mut Bencher) { + let mut rng = fastrand::Rng::new(); + b.iter(|| { + // Pick a size that isn't divisble by 8. + let mut bytes = [0u8; 367]; + rng.fill(&mut bytes); + bytes + }) +} + +#[bench] +fn fill_naive(b: &mut Bencher) { + let mut rng = fastrand::Rng::new(); + b.iter(|| { + let mut bytes = [0u8; 367]; + for item in &mut bytes { + *item = rng.u8(..); + } + bytes + }) +} -- cgit v1.2.3