diff --git a/benchmarks/src/btreemap.rs b/benchmarks/src/btreemap.rs index d280a167..43de5fd8 100644 --- a/benchmarks/src/btreemap.rs +++ b/benchmarks/src/btreemap.rs @@ -240,6 +240,46 @@ pub fn btreemap_iter_rev_10mib_values() -> BenchResult { iter_rev_helper(200, 10 * 1024) } +#[bench(raw)] +pub fn btreemap_keys_small_values() -> BenchResult { + keys_helper(10_000, 0) +} + +#[bench(raw)] +pub fn btreemap_keys_rev_small_values() -> BenchResult { + keys_rev_helper(10_000, 0) +} + +#[bench(raw)] +pub fn btreemap_keys_10mib_values() -> BenchResult { + keys_helper(200, 10 * 1024) +} + +#[bench(raw)] +pub fn btreemap_keys_rev_10mib_values() -> BenchResult { + keys_rev_helper(200, 10 * 1024) +} + +#[bench(raw)] +pub fn btreemap_values_small_values() -> BenchResult { + values_helper(10_000, 0) +} + +#[bench(raw)] +pub fn btreemap_values_rev_small_values() -> BenchResult { + values_rev_helper(10_000, 0) +} + +#[bench(raw)] +pub fn btreemap_values_10mib_values() -> BenchResult { + values_helper(200, 10 * 1024) +} + +#[bench(raw)] +pub fn btreemap_values_rev_10mib_values() -> BenchResult { + values_rev_helper(200, 10 * 1024) +} + #[bench(raw)] pub fn btreemap_iter_count_small_values() -> BenchResult { let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); @@ -557,6 +597,46 @@ fn iter_rev_helper(size: u32, value_size: u32) -> BenchResult { bench_fn(|| for _ in btree.iter().rev() {}) } +// Profiles iterating over the keys of a btreemap. +fn keys_helper(size: u32, value_size: u32) -> BenchResult { + let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); + for i in 0..size { + btree.insert(i, vec![0u8; value_size as usize]); + } + + bench_fn(|| for _ in btree.keys() {}) +} + +// Profiles iterating in reverse over the keys of a btreemap. +fn keys_rev_helper(size: u32, value_size: u32) -> BenchResult { + let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); + for i in 0..size { + btree.insert(i, vec![0u8; value_size as usize]); + } + + bench_fn(|| for _ in btree.keys().rev() {}) +} + +// Profiles iterating over the values of a btreemap. +fn values_helper(size: u32, value_size: u32) -> BenchResult { + let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); + for i in 0..size { + btree.insert(i, vec![0u8; value_size as usize]); + } + + bench_fn(|| for _ in btree.values() {}) +} + +// Profiles iterating in reverse over the values of a btreemap. +fn values_rev_helper(size: u32, value_size: u32) -> BenchResult { + let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); + for i in 0..size { + btree.insert(i, vec![0u8; value_size as usize]); + } + + bench_fn(|| for _ in btree.values().rev() {}) +} + // Profiles getting a large number of random blobs from a btreemap. fn get_blob_helper() -> BenchResult { let btree = BTreeMap::new_v1(DefaultMemoryImpl::default()); diff --git a/canbench_results.yml b/canbench_results.yml index 830313c6..9ee52cc3 100644 --- a/canbench_results.yml +++ b/canbench_results.yml @@ -385,13 +385,13 @@ benches: scopes: {} btreemap_iter_rev_10mib_values: total: - instructions: 25585550 + instructions: 25584039 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_iter_rev_small_values: total: - instructions: 23878236 + instructions: 23800315 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -401,6 +401,30 @@ benches: heap_increase: 0 stable_memory_increase: 0 scopes: {} + btreemap_keys_10mib_values: + total: + instructions: 534290 + heap_increase: 0 + stable_memory_increase: 0 + scopes: {} + btreemap_keys_rev_10mib_values: + total: + instructions: 595467 + heap_increase: 0 + stable_memory_increase: 0 + scopes: {} + btreemap_keys_rev_small_values: + total: + instructions: 14369449 + heap_increase: 0 + stable_memory_increase: 0 + scopes: {} + btreemap_keys_small_values: + total: + instructions: 11184261 + heap_increase: 0 + stable_memory_increase: 0 + scopes: {} btreemap_remove_blob_128_1024: total: instructions: 1916049094 @@ -533,6 +557,30 @@ benches: heap_increase: 0 stable_memory_increase: 0 scopes: {} + btreemap_values_10mib_values: + total: + instructions: 17277830 + heap_increase: 0 + stable_memory_increase: 0 + scopes: {} + btreemap_values_rev_10mib_values: + total: + instructions: 17276742 + heap_increase: 0 + stable_memory_increase: 0 + scopes: {} + btreemap_values_rev_small_values: + total: + instructions: 22619653 + heap_increase: 0 + stable_memory_increase: 0 + scopes: {} + btreemap_values_small_values: + total: + instructions: 22560352 + heap_increase: 0 + stable_memory_increase: 0 + scopes: {} memory_manager_baseline: total: instructions: 1176577052 @@ -541,13 +589,13 @@ benches: scopes: {} memory_manager_grow: total: - instructions: 350727867 + instructions: 351687872 heap_increase: 2 stable_memory_increase: 32000 scopes: {} memory_manager_overhead: total: - instructions: 1182141676 + instructions: 1182143127 heap_increase: 0 stable_memory_increase: 8320 scopes: {}