aboutsummaryrefslogtreecommitdiff
path: root/src/tests/example_sets
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/example_sets')
-rw-r--r--src/tests/example_sets/benches/main.rs6
-rw-r--r--src/tests/example_sets/src/lib.rs8
2 files changed, 8 insertions, 6 deletions
diff --git a/src/tests/example_sets/benches/main.rs b/src/tests/example_sets/benches/main.rs
index 26e8547..03ab904 100644
--- a/src/tests/example_sets/benches/main.rs
+++ b/src/tests/example_sets/benches/main.rs
@@ -1,12 +1,14 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
+use rand::{rngs::StdRng, SeedableRng};
fn run_benches(c: &mut Criterion) {
- for size in [500, 2_000, 10_000, 50_000].iter() {
+ let mut rng = StdRng::seed_from_u64(42);
+ for size in [50, 150, 2_500, 7_500].iter() {
c.bench_with_input(
BenchmarkId::new("example_sets-insert_n", size),
size,
|b, &n| {
- b.iter(|| example_sets::insert_n(n));
+ b.iter(|| example_sets::insert_n(&mut rng, n));
},
);
}
diff --git a/src/tests/example_sets/src/lib.rs b/src/tests/example_sets/src/lib.rs
index c5bd163..5acd6d7 100644
--- a/src/tests/example_sets/src/lib.rs
+++ b/src/tests/example_sets/src/lib.rs
@@ -4,17 +4,17 @@ mod types;
use types::Set;
use primrose_library::traits::*;
-use rand::random;
+use rand::{rngs::StdRng, Rng};
use std::hint::black_box;
-pub fn insert_n(n: usize) {
+pub fn insert_n(rng: &mut StdRng, n: usize) {
let mut set: Set<usize> = Set::default();
for _ in 0..n {
- set.insert(random());
+ set.insert(rng.gen());
}
for _ in 0..2 * n {
- black_box(|x| x)(black_box(set.contains(&random())));
+ black_box(|x| x)(black_box(set.contains(&rng.gen())));
}
}