From abd9d0661b6aabb8714aa63b1c01d58c99ec372c Mon Sep 17 00:00:00 2001 From: David Frank Date: Mon, 18 Nov 2024 12:48:14 +0000 Subject: [PATCH 1/4] test: Add two new benchmarks for benchmarking situations where not every value is read Later PRs will optimize these scenarios. --- benchmarks/src/btreemap.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/benchmarks/src/btreemap.rs b/benchmarks/src/btreemap.rs index 5e1e92f3..a65d8a9f 100644 --- a/benchmarks/src/btreemap.rs +++ b/benchmarks/src/btreemap.rs @@ -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_entries() -> 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::() + }) +} + +// Read a range of entries but only process the value from every third entry. +#[bench(raw)] +pub fn btreemap_read_every_third_value() -> 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::() + }) +} + #[bench(raw)] pub fn btreemap_iter_count_small_values() -> BenchResult { let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); From 32f05daed338e7743a65611e26755a79fbd8cce9 Mon Sep 17 00:00:00 2001 From: David Frank Date: Mon, 18 Nov 2024 12:52:42 +0000 Subject: [PATCH 2/4] Rename and update canbench --- canbench_results.yml | 138 +++++++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 63 deletions(-) diff --git a/canbench_results.yml b/canbench_results.yml index 76f2bee3..130712a4 100644 --- a/canbench_results.yml +++ b/canbench_results.yml @@ -133,235 +133,235 @@ benches: scopes: {} btreemap_insert_10mib_values: total: - instructions: 145812477 + instructions: 145922325 heap_increase: 0 stable_memory_increase: 32 scopes: {} btreemap_insert_blob_1024_128: total: - instructions: 5161897359 + instructions: 5161914701 heap_increase: 0 stable_memory_increase: 262 scopes: {} btreemap_insert_blob_1024_128_v2: total: - instructions: 5551050739 + instructions: 5551068081 heap_increase: 0 stable_memory_increase: 196 scopes: {} btreemap_insert_blob_1024_16: total: - instructions: 5117351375 + instructions: 5117369042 heap_increase: 0 stable_memory_increase: 241 scopes: {} btreemap_insert_blob_1024_16_v2: total: - instructions: 5508484410 + instructions: 5508502115 heap_increase: 0 stable_memory_increase: 181 scopes: {} btreemap_insert_blob_1024_256: total: - instructions: 5184887283 + instructions: 5184904755 heap_increase: 0 stable_memory_increase: 292 scopes: {} btreemap_insert_blob_1024_256_v2: total: - instructions: 5574297530 + instructions: 5574315002 heap_increase: 0 stable_memory_increase: 219 scopes: {} btreemap_insert_blob_1024_32: total: - instructions: 5124591897 + instructions: 5124609174 heap_increase: 0 stable_memory_increase: 239 scopes: {} btreemap_insert_blob_1024_32_v2: total: - instructions: 5514794407 + instructions: 5514811773 heap_increase: 0 stable_memory_increase: 180 scopes: {} btreemap_insert_blob_1024_4: total: - instructions: 5013226971 + instructions: 5013244404 heap_increase: 0 stable_memory_increase: 235 scopes: {} btreemap_insert_blob_1024_4_v2: total: - instructions: 5408556192 + instructions: 5408573739 heap_increase: 0 stable_memory_increase: 176 scopes: {} btreemap_insert_blob_1024_512: total: - instructions: 5296477642 + instructions: 5296495023 heap_increase: 0 stable_memory_increase: 348 scopes: {} btreemap_insert_blob_1024_512_v2: total: - instructions: 5692592790 + instructions: 5692610171 heap_increase: 0 stable_memory_increase: 261 scopes: {} btreemap_insert_blob_1024_64: total: - instructions: 5160666685 + instructions: 5160684248 heap_increase: 0 stable_memory_increase: 250 scopes: {} btreemap_insert_blob_1024_64_v2: total: - instructions: 5550334403 + instructions: 5550351966 heap_increase: 0 stable_memory_increase: 188 scopes: {} btreemap_insert_blob_1024_8: total: - instructions: 5098581170 + instructions: 5098598668 heap_increase: 0 stable_memory_increase: 237 scopes: {} btreemap_insert_blob_1024_8_v2: total: - instructions: 5491442141 + instructions: 5491459791 heap_increase: 0 stable_memory_increase: 178 scopes: {} btreemap_insert_blob_128_1024: total: - instructions: 1521313518 + instructions: 1521330782 heap_increase: 0 stable_memory_increase: 260 scopes: {} btreemap_insert_blob_128_1024_v2: total: - instructions: 1651648946 + instructions: 1651666210 heap_increase: 0 stable_memory_increase: 195 scopes: {} btreemap_insert_blob_16_1024: total: - instructions: 914649153 + instructions: 914664896 heap_increase: 0 stable_memory_increase: 215 scopes: {} btreemap_insert_blob_16_1024_v2: total: - instructions: 1012886554 + instructions: 1012902411 heap_increase: 0 stable_memory_increase: 161 scopes: {} btreemap_insert_blob_256_1024: total: - instructions: 2072274900 + instructions: 2072292372 heap_increase: 0 stable_memory_increase: 292 scopes: {} btreemap_insert_blob_256_1024_v2: total: - instructions: 2262444663 + instructions: 2262462135 heap_increase: 0 stable_memory_increase: 219 scopes: {} btreemap_insert_blob_32_1024: total: - instructions: 971181545 + instructions: 971198185 heap_increase: 0 stable_memory_increase: 230 scopes: {} btreemap_insert_blob_32_1024_v2: total: - instructions: 1063753591 + instructions: 1063770231 heap_increase: 0 stable_memory_increase: 173 scopes: {} btreemap_insert_blob_4_1024: total: - instructions: 702280030 + instructions: 702289156 heap_increase: 0 stable_memory_increase: 123 scopes: {} btreemap_insert_blob_4_1024_v2: total: - instructions: 787268408 + instructions: 787277534 heap_increase: 0 stable_memory_increase: 92 scopes: {} btreemap_insert_blob_512_1024: total: - instructions: 3204802664 + instructions: 3204820188 heap_increase: 0 stable_memory_increase: 351 scopes: {} btreemap_insert_blob_512_1024_v2: total: - instructions: 3464684781 + instructions: 3464702305 heap_increase: 0 stable_memory_increase: 263 scopes: {} btreemap_insert_blob_64_1024: total: - instructions: 1242001761 + instructions: 1242018908 heap_increase: 0 stable_memory_increase: 245 scopes: {} btreemap_insert_blob_64_1024_v2: total: - instructions: 1345180958 + instructions: 1345198105 heap_increase: 0 stable_memory_increase: 183 scopes: {} btreemap_insert_blob_8_1024: total: - instructions: 828098541 + instructions: 828112100 heap_increase: 0 stable_memory_increase: 183 scopes: {} btreemap_insert_blob_8_1024_v2: total: - instructions: 919884588 + instructions: 919898223 heap_increase: 0 stable_memory_increase: 138 scopes: {} btreemap_insert_blob_8_u64: total: - instructions: 424320990 + instructions: 424334575 heap_increase: 0 stable_memory_increase: 6 scopes: {} btreemap_insert_blob_8_u64_v2: total: - instructions: 524532367 + instructions: 524551164 heap_increase: 0 stable_memory_increase: 4 scopes: {} btreemap_insert_u64_blob_8: total: - instructions: 435841221 + instructions: 435858693 heap_increase: 0 stable_memory_increase: 7 scopes: {} btreemap_insert_u64_blob_8_v2: total: - instructions: 502367747 + instructions: 502390007 heap_increase: 0 stable_memory_increase: 5 scopes: {} btreemap_insert_u64_u64: total: - instructions: 448311336 + instructions: 448328834 heap_increase: 0 stable_memory_increase: 7 scopes: {} btreemap_insert_u64_u64_v2: total: - instructions: 518585831 + instructions: 518609796 heap_increase: 0 stable_memory_increase: 6 scopes: {} @@ -376,136 +376,148 @@ benches: instructions: 10242765 heap_increase: 0 stable_memory_increase: 0 + scopes: { } + btreemap_read_every_third_value_from_range: + total: + instructions: 174611905 + heap_increase: 0 + stable_memory_increase: 0 + scopes: { } + btreemap_read_keys_from_range: + total: + instructions: 174611905 + heap_increase: 0 + stable_memory_increase: 0 scopes: {} btreemap_remove_blob_128_1024: total: - instructions: 1916023862 + instructions: 1916049094 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_128_1024_v2: total: - instructions: 2060123740 + instructions: 2060148972 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_16_1024: total: - instructions: 1174997981 + instructions: 1175020990 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_16_1024_v2: total: - instructions: 1310740941 + instructions: 1310763950 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_256_1024: total: - instructions: 2563712145 + instructions: 2563737681 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_256_1024_v2: total: - instructions: 2714997748 + instructions: 2715023284 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_32_1024: total: - instructions: 1257954087 + instructions: 1257978407 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_32_1024_v2: total: - instructions: 1396007710 + instructions: 1396032068 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_4_1024: total: - instructions: 730539960 + instructions: 730553298 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_4_1024_v2: total: - instructions: 832319712 + instructions: 832333088 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_512_1024: total: - instructions: 3925463425 + instructions: 3925489037 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_512_1024_v2: total: - instructions: 4079794221 + instructions: 4079819871 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_64_1024: total: - instructions: 1579833528 + instructions: 1579858589 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_64_1024_v2: total: - instructions: 1719825276 + instructions: 1719850337 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_8_1024: total: - instructions: 958306352 + instructions: 958326169 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_8_1024_v2: total: - instructions: 1076045855 + instructions: 1076065710 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_8_u64: total: - instructions: 549451611 + instructions: 549471466 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_blob_8_u64_v2: total: - instructions: 685586627 + instructions: 685613050 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_u64_blob_8: total: - instructions: 609355138 + instructions: 609380674 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_u64_blob_8_v2: total: - instructions: 705661181 + instructions: 705692037 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_u64_u64: total: - instructions: 634545364 + instructions: 634570938 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_remove_u64_u64_v2: total: - instructions: 739907256 + instructions: 739939423 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -517,13 +529,13 @@ benches: scopes: {} memory_manager_grow: total: - instructions: 352839872 + instructions: 351687872 heap_increase: 2 stable_memory_increase: 32000 scopes: {} memory_manager_overhead: total: - instructions: 1182161127 + instructions: 1182143127 heap_increase: 0 stable_memory_increase: 8320 scopes: {} From efbc37f6d909440998873480c68fb4111bb82251 Mon Sep 17 00:00:00 2001 From: David Frank Date: Mon, 18 Nov 2024 12:55:12 +0000 Subject: [PATCH 3/4] Canbench --- benchmarks/src/btreemap.rs | 4 ++-- canbench_results.yml | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/benchmarks/src/btreemap.rs b/benchmarks/src/btreemap.rs index 9815fec1..01214fae 100644 --- a/benchmarks/src/btreemap.rs +++ b/benchmarks/src/btreemap.rs @@ -222,7 +222,7 @@ 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_entries() -> BenchResult { +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 { @@ -239,7 +239,7 @@ pub fn btreemap_read_keys_from_entries() -> BenchResult { // Read a range of entries but only process the value from every third entry. #[bench(raw)] -pub fn btreemap_read_every_third_value() -> BenchResult { +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 { diff --git a/canbench_results.yml b/canbench_results.yml index 9ee52cc3..c320e798 100644 --- a/canbench_results.yml +++ b/canbench_results.yml @@ -425,6 +425,18 @@ benches: heap_increase: 0 stable_memory_increase: 0 scopes: {} + btreemap_read_every_third_value_from_range: + total: + instructions: 167219433 + heap_increase: 0 + stable_memory_increase: 0 + scopes: { } + btreemap_read_keys_from_range: + total: + instructions: 167219433 + heap_increase: 0 + stable_memory_increase: 0 + scopes: { } btreemap_remove_blob_128_1024: total: instructions: 1916049094 From f826d605aea2b6baee7cb37784e78f75409f0d78 Mon Sep 17 00:00:00 2001 From: David Frank Date: Mon, 18 Nov 2024 13:42:38 +0000 Subject: [PATCH 4/4] Canbench --- canbench_results.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/canbench_results.yml b/canbench_results.yml index 90558fff..bd1995fe 100644 --- a/canbench_results.yml +++ b/canbench_results.yml @@ -427,13 +427,13 @@ benches: scopes: {} btreemap_read_every_third_value_from_range: total: - instructions: 167219433 + instructions: 160211242 heap_increase: 0 stable_memory_increase: 0 scopes: { } btreemap_read_keys_from_range: total: - instructions: 167219433 + instructions: 160211242 heap_increase: 0 stable_memory_increase: 0 scopes: { }