diff options
author | Aria Shrimpton <me@aria.rip> | 2024-03-19 22:38:59 +0000 |
---|---|---|
committer | Aria Shrimpton <me@aria.rip> | 2024-03-19 22:38:59 +0000 |
commit | 18be480e89e773f827da930d98618db4a9c9d9f9 (patch) | |
tree | 1ec5ed902a9e40b136c0e8f3d59d241816e719c5 /src/tests/example_mapping | |
parent | 05715322ad643b39234e0d2f752acc762e760b35 (diff) |
benchmark updates
Diffstat (limited to 'src/tests/example_mapping')
-rw-r--r-- | src/tests/example_mapping/benches/main.rs | 6 | ||||
-rw-r--r-- | src/tests/example_mapping/src/lib.rs | 12 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/tests/example_mapping/benches/main.rs b/src/tests/example_mapping/benches/main.rs index 04d43fb..77b2394 100644 --- a/src/tests/example_mapping/benches/main.rs +++ b/src/tests/example_mapping/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 [10_000, 30_000, 60_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_mapping-insert_get", size), size, |b, &n| { - b.iter(|| example_mapping::insert_get(n)); + b.iter(|| example_mapping::insert_get(&mut rng, n)); }, ); } diff --git a/src/tests/example_mapping/src/lib.rs b/src/tests/example_mapping/src/lib.rs index f9216df..c95a016 100644 --- a/src/tests/example_mapping/src/lib.rs +++ b/src/tests/example_mapping/src/lib.rs @@ -2,18 +2,18 @@ mod types; use primrose_library::traits::Mapping; -use rand::random; +use rand::{rngs::StdRng, Rng}; use std::hint::black_box; use types::*; -pub fn insert_get(n: usize) { - let mut set: Map<String, usize> = Map::default(); +pub fn insert_get(rng: &mut StdRng, n: usize) { + let mut set: Map<usize, usize> = Map::default(); - for i in 0..n { - set.insert(i.to_string(), random()); + for _ in 0..n { + set.insert(rng.gen(), rng.gen()); } for i in 0..2 * n { - black_box(|x| x)(black_box(set.get(&i.to_string()))); + black_box(|x| x)(black_box(set.get(&i))); } } |