aboutsummaryrefslogtreecommitdiff
path: root/src/crates
diff options
context:
space:
mode:
Diffstat (limited to 'src/crates')
-rw-r--r--src/crates/benchmarker/src/mapping.rs36
-rw-r--r--src/crates/candelabra/src/cost/benchmark.rs2
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