diff options
author | Aria Shrimpton <me@aria.rip> | 2024-03-10 15:57:47 +0000 |
---|---|---|
committer | Aria Shrimpton <me@aria.rip> | 2024-03-10 15:59:33 +0000 |
commit | 42f7e8a65609122d459e15aa5dce7d7abe95d989 (patch) | |
tree | 8b0579792b7cc38f60ce11dd3e8890a2a910d645 /src | |
parent | 7fc1f3d585bea58731409e4b3e62599f4975d8e1 (diff) |
benchmark very small n values, and add mapping.get benchmarks
Diffstat (limited to 'src')
-rw-r--r-- | src/crates/benchmarker/src/mapping.rs | 36 | ||||
-rw-r--r-- | src/crates/candelabra/src/cost/benchmark.rs | 2 |
2 files changed, 37 insertions, 1 deletions
diff --git a/src/crates/benchmarker/src/mapping.rs b/src/crates/benchmarker/src/mapping.rs index 9c3d467..964f633 100644 --- a/src/crates/benchmarker/src/mapping.rs +++ b/src/crates/benchmarker/src/mapping.rs @@ -4,6 +4,7 @@ use rand::{ rngs::StdRng, Rng, }; +use std::hint::black_box; use crate::{benchmark_op, print_results}; @@ -16,6 +17,7 @@ where { for n in ns { scenario_populate::<T, K, V>(rng, *n); + scenario_get::<T, K, V>(rng, *n); scenario_contains::<T, K, V>(rng, *n); scenario_remove::<T, K, V>(rng, *n); scenario_clear::<T, K, V>(rng, *n); @@ -51,6 +53,40 @@ where print_results("insert", n, &results); } +fn scenario_get<T, K, V>(rng: &mut StdRng, n: usize) +where + T: Mapping<K, V> + Default + Clone, + K: Copy, + V: Copy, + Standard: Distribution<K> + Distribution<V>, +{ + let results = benchmark_op( + || { + let mut c = T::default(); + + // decide where the element that we will search for will be + let pivot = rng.gen_range(0..n); + + // insert the element at pivot, and keep track of what it is + for _ in 0..pivot { + c.insert(rng.gen(), rng.gen()); + } + let chosen = rng.gen(); + c.insert(chosen, rng.gen()); + for _ in pivot..n { + c.insert(rng.gen(), rng.gen()); + } + + (c, chosen) + }, + |(c, chosen)| { + black_box(c.get(chosen)); + }, + ); + + print_results("get", n, &results); +} + fn scenario_contains<T, K, V>(rng: &mut StdRng, n: usize) where T: Mapping<K, V> + Default + Clone, diff --git a/src/crates/candelabra/src/cost/benchmark.rs b/src/crates/candelabra/src/cost/benchmark.rs index 45bac5d..812b023 100644 --- a/src/crates/candelabra/src/cost/benchmark.rs +++ b/src/crates/candelabra/src/cost/benchmark.rs @@ -25,7 +25,7 @@ pub const ELEM_TYPE: &str = "usize"; /// String representation of the array of N values we use for benchmarking pub const NS: &str = "[ - 100, 500, 6_000, 12_000, 24_000, 36_000, 48_000, 60_000 + 10, 100, 500, 6_000, 12_000, 24_000, 36_000, 48_000, 60_000 ]"; /// Fixed seed for benchmarking |