From 42f7e8a65609122d459e15aa5dce7d7abe95d989 Mon Sep 17 00:00:00 2001 From: Aria Shrimpton Date: Sun, 10 Mar 2024 15:57:47 +0000 Subject: benchmark very small n values, and add mapping.get benchmarks --- src/crates/benchmarker/src/mapping.rs | 36 +++++++++++++++++++++++++++++ src/crates/candelabra/src/cost/benchmark.rs | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'src/crates') 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::(rng, *n); + scenario_get::(rng, *n); scenario_contains::(rng, *n); scenario_remove::(rng, *n); scenario_clear::(rng, *n); @@ -51,6 +53,40 @@ where print_results("insert", n, &results); } +fn scenario_get(rng: &mut StdRng, n: usize) +where + T: Mapping + Default + Clone, + K: Copy, + V: Copy, + Standard: Distribution + Distribution, +{ + 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(rng: &mut StdRng, n: usize) where T: Mapping + 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 -- cgit v1.2.3