Skip to content

Commit

Permalink
Add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Nov 13, 2024
1 parent 226ffbd commit 2b32296
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 4 deletions.
80 changes: 80 additions & 0 deletions benchmarks/src/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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<const K: usize, const V: usize>() -> BenchResult {
let btree = BTreeMap::new_v1(DefaultMemoryImpl::default());
Expand Down
56 changes: 52 additions & 4 deletions canbench_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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: {}
Expand Down

0 comments on commit 2b32296

Please sign in to comment.