Skip to content
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

perf: BTreeMap: make range().count() more efficient #190

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2c8e0aa
.
dragoljub-duric Feb 7, 2024
d205b6e
fix clippy
dragoljub-duric Feb 7, 2024
38dc7b5
Add benchmark
dragoljub-duric Feb 7, 2024
1858ceb
Fix next_without_loading_value().
dragoljub-duric Feb 8, 2024
edce423
Make iter_count_test a proptest.
dragoljub-duric Feb 8, 2024
c1c0a56
.
dragoljub-duric Feb 8, 2024
e549d7f
.
dragoljub-duric Feb 8, 2024
e58b408
.
dragoljub-duric Feb 8, 2024
9fad566
fix proptest
dragoljub-duric Feb 8, 2024
1e17542
Recatro iter without code duplication.
dragoljub-duric Feb 8, 2024
aa45bf3
.
dragoljub-duric Feb 9, 2024
b328ff6
.
dragoljub-duric Feb 9, 2024
404a481
Update benchmarks/src/btreemap.rs
dragoljub-duric Feb 9, 2024
86c99bc
Apply comments
dragoljub-duric Feb 9, 2024
409270d
Merge branch 'Add_iter_count_benches' into EXC-1548-b-tree-map-make-r…
dragoljub-duric Feb 9, 2024
6c9acf2
Rerun benches
dragoljub-duric Feb 9, 2024
2fd5bc9
Merge branch 'EXC-1553-upgrade-rust-version-in-stable-structures-ci' …
dragoljub-duric Feb 9, 2024
e90542f
Merge branch 'Add_iter_count_benches' into EXC-1548-b-tree-map-make-r…
dragoljub-duric Feb 9, 2024
c0de7f2
.
dragoljub-duric Feb 12, 2024
84c70c4
refactor next_internal to avoid cloning
dragoljub-duric Feb 12, 2024
f56cfc8
remove Clone
dragoljub-duric Feb 12, 2024
ea9dc95
Merge branch 'main' into EXC-1548-b-tree-map-make-range-count-more-ef…
dragoljub-duric Feb 12, 2024
b1640ff
cnabench_results from main
dragoljub-duric Feb 13, 2024
358f4ab
.
dragoljub-duric Feb 13, 2024
9ca6ba6
move test to btreemap/proptests.rs
dragoljub-duric Feb 13, 2024
d032bb5
rerun canbench
dragoljub-duric Feb 13, 2024
83a6418
clippy
dragoljub-duric Feb 13, 2024
46d9893
Adress comment
dragoljub-duric Feb 13, 2024
55d9b22
Update src/btreemap/iter.rs
dragoljub-duric Feb 14, 2024
b658417
Apply suggestion from comments.
dragoljub-duric Feb 14, 2024
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
29 changes: 29 additions & 0 deletions benchmarks/src/btreemap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::Random;
use canbench::{benchmark, macros::bench, BenchResult};
use ic_stable_structures::{storable::Blob, BTreeMap, DefaultMemoryImpl, Storable};
use std::ops::Bound;
use tiny_rng::{Rand, Rng};

#[bench]
Expand Down Expand Up @@ -219,6 +220,34 @@ pub fn btreemap_insert_10mib_values() -> BenchResult {
})
}

#[bench]
pub fn btreemap_iter_count() -> BenchResult {
dragoljub-duric marked this conversation as resolved.
Show resolved Hide resolved
let mut btree = BTreeMap::new(DefaultMemoryImpl::default());

// Insert 200 10MiB values.
let mut rng = Rng::from_seed(0);
let mut values = vec![];
for _ in 0..200 {
values.push(rng.iter(Rand::rand_u8).take(10 * 1024).collect::<Vec<_>>());
}

let mut i = 0u8;
for value in values.into_iter() {
btree.insert(i, value);
i += 1;
}

benchmark(|| {
for j in 0..i {
for k in j + 1..i {
btree
.range((Bound::Included(j), Bound::Included(k)))
.count();
}
}
})
}

/// Benchmarks removing keys from a BTreeMap.
#[bench]
pub fn btreemap_remove_blob_4_1024() -> BenchResult {
Expand Down
Loading
Loading