Skip to content

test: Add two new benchmarks for benchmarking situations where not every value is read #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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