Skip to content

Commit

Permalink
perf: Add benchmarks for BtreeMap::Iterator::count() (#191)
Browse files Browse the repository at this point in the history
Co-authored-by: Islam El-Ashi <islam.elashi@dfinity.org>
  • Loading branch information
dragoljub-duric and ielashi authored Feb 12, 2024
1 parent 5ac483a commit daeb0a5
Show file tree
Hide file tree
Showing 2 changed files with 289 additions and 244 deletions.
35 changes: 35 additions & 0 deletions benchmarks/src/btreemap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Bound;

use crate::Random;
use canbench::{benchmark, macros::bench, BenchResult};
use ic_stable_structures::{storable::Blob, BTreeMap, DefaultMemoryImpl, Storable};
Expand Down Expand Up @@ -219,6 +221,39 @@ pub fn btreemap_insert_10mib_values() -> BenchResult {
})
}

#[bench]
pub fn btreemap_iter_count_small_values() -> BenchResult {
let mut btree = BTreeMap::new(DefaultMemoryImpl::default());
let size: u32 = 10_000;
for i in 0..size {
btree.insert(i, vec![]);
}

benchmark(|| {
btree
.range((Bound::Included(0), Bound::Included(size)))
.count();
})
}

#[bench]
pub fn btreemap_iter_count_10mib_values() -> BenchResult {
let mut btree = BTreeMap::new(DefaultMemoryImpl::default());

let size: u8 = 200;

// Insert 200 10MiB values.
for i in 0..size {
btree.insert(i, vec![0u8; 10 * 1024]);
}

benchmark(|| {
btree
.range((Bound::Included(0), Bound::Included(size)))
.count();
})
}

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

0 comments on commit daeb0a5

Please # to comment.