Skip to content

Commit

Permalink
test: Add two new benchmarks for benchmarking situations where not ev…
Browse files Browse the repository at this point in the history
…ery value is read (#243)

Later PRs will optimize these scenarios.
  • Loading branch information
frankdavid authored Nov 18, 2024
1 parent 1f75f43 commit 0814d4b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
35 changes: 35 additions & 0 deletions benchmarks/src/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,41 @@ pub fn btreemap_insert_10mib_values() -> BenchResult {
})
}

// Read a range of entries but only process the key of each entry.
#[bench(raw)]
pub fn btreemap_read_keys_from_range() -> BenchResult {
let mut btree = BTreeMap::new(DefaultMemoryImpl::default());
let size: u32 = 10_000;
for i in 0..size {
btree.insert(i, vec![0; 1024]);
}

bench_fn(|| {
btree
.range((Bound::Included(0), Bound::Included(size)))
.map(|entry| entry.0)
.sum::<u32>()
})
}

// Read a range of entries but only process the value from every third entry.
#[bench(raw)]
pub fn btreemap_read_every_third_value_from_range() -> BenchResult {
let mut btree = BTreeMap::new(DefaultMemoryImpl::default());
let size: u32 = 10_000;
for i in 0..size {
btree.insert(i, vec![0; 1024]);
}

bench_fn(|| {
btree
.range((Bound::Included(0), Bound::Included(size)))
.filter(|entry| entry.0 % 3 == 0)
.map(|entry| entry.1.len())
.sum::<usize>()
})
}

#[bench(raw)]
pub fn btreemap_iter_small_values() -> BenchResult {
iter_helper(10_000, 0, IterType::Iter)
Expand Down
12 changes: 12 additions & 0 deletions canbench_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ benches:
heap_increase: 0
stable_memory_increase: 0
scopes: {}
btreemap_read_every_third_value_from_range:
total:
instructions: 160211242
heap_increase: 0
stable_memory_increase: 0
scopes: { }
btreemap_read_keys_from_range:
total:
instructions: 160211242
heap_increase: 0
stable_memory_increase: 0
scopes: { }
btreemap_remove_blob_128_1024:
total:
instructions: 1842207367
Expand Down

0 comments on commit 0814d4b

Please sign in to comment.