summaryrefslogtreecommitdiffstats
path: root/third_party/rust/fastrand/benches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/fastrand/benches
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/fastrand/benches')
-rw-r--r--third_party/rust/fastrand/benches/bench.rs98
1 files changed, 98 insertions, 0 deletions
diff --git a/third_party/rust/fastrand/benches/bench.rs b/third_party/rust/fastrand/benches/bench.rs
new file mode 100644
index 0000000000..4b882b74f9
--- /dev/null
+++ b/third_party/rust/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::<Vec<usize>>();
+ b.iter(|| {
+ x.shuffle(&mut rng);
+ x[0]
+ })
+}
+
+#[bench]
+fn shuffle_fastrand(b: &mut Bencher) {
+ let rng = fastrand::Rng::new();
+ let mut x = (0..100).collect::<Vec<usize>>();
+ 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::<u8>());
+ }
+ sum
+ })
+}
+
+#[bench]
+fn u8_fastrand(b: &mut Bencher) {
+ let 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::<u32>());
+ }
+ sum
+ })
+}
+
+#[bench]
+fn u32_fastrand(b: &mut Bencher) {
+ let 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 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 rng = fastrand::Rng::new();
+ b.iter(|| {
+ let mut bytes = [0u8; 367];
+ for item in &mut bytes {
+ *item = rng.u8(..);
+ }
+ bytes
+ })
+}