diff --git a/benchmarks/src/btreemap.rs b/benchmarks/src/btreemap.rs index 868dbd91..39f5ed8b 100644 --- a/benchmarks/src/btreemap.rs +++ b/benchmarks/src/btreemap.rs @@ -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}; @@ -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 { diff --git a/canbench_results.yml b/canbench_results.yml index 8ad5889d..cdad989b 100644 --- a/canbench_results.yml +++ b/canbench_results.yml @@ -1,544 +1,554 @@ btreemap_get_blob_128_1024: measurements: - instructions: 1006573538 - node_load_v1: 832328557 + instructions: 918297550 + node_load_v1: 754035202 stable_memory_size: 261 btreemap_get_blob_128_1024_v2: measurements: - instructions: 1123805990 - node_load_v2: 938155476 + instructions: 1012404828 + node_load_v2: 838471112 stable_memory_size: 196 btreemap_get_blob_16_1024: measurements: - instructions: 487229806 - node_load_v1: 339804418 + instructions: 402489372 + node_load_v1: 265476351 stable_memory_size: 216 btreemap_get_blob_16_1024_v2: measurements: - instructions: 583474971 - node_load_v2: 430852270 + instructions: 483065575 + node_load_v2: 341517378 stable_memory_size: 162 btreemap_get_blob_256_1024: measurements: - instructions: 1510660940 - node_load_v1: 1309093774 + instructions: 1419922692 + node_load_v1: 1228326401 stable_memory_size: 293 btreemap_get_blob_256_1024_v2: measurements: - instructions: 1626341678 - node_load_v2: 1410845462 + instructions: 1514269692 + node_load_v2: 1310914461 stable_memory_size: 220 btreemap_get_blob_32_1024: measurements: - instructions: 534895222 - node_load_v1: 378516147 + instructions: 445863040 + node_load_v1: 300380122 stable_memory_size: 231 btreemap_get_blob_32_1024_v2: measurements: - instructions: 633048491 - node_load_v2: 471574348 + instructions: 526615123 + node_load_v2: 376711582 stable_memory_size: 174 btreemap_get_blob_4_1024: measurements: - instructions: 355650535 - node_load_v1: 231720942 + instructions: 276611192 + node_load_v1: 161238932 stable_memory_size: 124 btreemap_get_blob_4_1024_v2: measurements: - instructions: 446660432 - node_load_v2: 313869359 + instructions: 355490148 + node_load_v2: 232414919 stable_memory_size: 93 btreemap_get_blob_512_1024: measurements: - instructions: 2506597898 - node_load_v1: 2251570705 + instructions: 2415920006 + node_load_v1: 2170866594 stable_memory_size: 352 btreemap_get_blob_512_1024_v2: measurements: - instructions: 2625838052 - node_load_v2: 2356816367 + instructions: 2511422025 + node_load_v2: 2254559660 stable_memory_size: 264 btreemap_get_blob_64_1024: measurements: - instructions: 780061526 - node_load_v1: 616669297 + instructions: 688360199 + node_load_v1: 535401984 stable_memory_size: 246 btreemap_get_blob_64_1024_v2: measurements: - instructions: 878745163 - node_load_v2: 706540951 + instructions: 769311566 + node_load_v2: 608827767 stable_memory_size: 184 btreemap_get_blob_8_1024: measurements: - instructions: 406432578 - node_load_v1: 259168629 + instructions: 324971280 + node_load_v1: 187633627 stable_memory_size: 184 btreemap_get_blob_8_1024_v2: measurements: - instructions: 493282925 - node_load_v2: 336415667 + instructions: 402008927 + node_load_v2: 256407446 stable_memory_size: 139 btreemap_get_blob_8_u64: measurements: - instructions: 368106593 - node_load_v1: 253569163 + instructions: 293440780 + node_load_v1: 187956979 stable_memory_size: 7 btreemap_get_blob_8_u64_v2: measurements: - instructions: 466009078 - node_load_v2: 345475118 + instructions: 372798113 + node_load_v2: 262576982 stable_memory_size: 5 btreemap_get_u64_blob_8: measurements: - instructions: 351156467 - node_load_v1: 250986516 + instructions: 274218978 + node_load_v1: 182442985 stable_memory_size: 8 btreemap_get_u64_blob_8_v2: measurements: - instructions: 413554294 - node_load_v2: 309705639 + instructions: 331020864 + node_load_v2: 236444481 stable_memory_size: 6 btreemap_get_u64_u64: measurements: - instructions: 353621464 - node_load_v1: 249502481 + instructions: 276850992 + node_load_v1: 181567530 stable_memory_size: 8 btreemap_get_u64_u64_v2: measurements: - instructions: 422146359 - node_load_v2: 312364993 + instructions: 338418081 + node_load_v2: 238660311 stable_memory_size: 7 btreemap_insert_10mib_values: measurements: - instructions: 107942355 - node_load_v2: 10057317 - node_save_v2: 77823608 + instructions: 99997294 + node_load_v2: 7855891 + node_save_v2: 72799502 stable_memory_size: 33 btreemap_insert_blob_1024_128: measurements: - instructions: 5115889431 - node_load_v1: 4062772095 - node_save_v1: 185771186 + instructions: 4984105840 + node_load_v1: 3988909453 + node_save_v1: 146460142 stable_memory_size: 263 btreemap_insert_blob_1024_128_v2: measurements: - instructions: 5394772440 - node_load_v2: 4190686429 - node_save_v2: 206085822 + instructions: 5239604456 + node_load_v2: 4090603010 + node_save_v2: 171846832 stable_memory_size: 197 btreemap_insert_blob_1024_16: measurements: - instructions: 5074839717 - node_load_v1: 4058526995 - node_save_v1: 172957200 + instructions: 4944664880 + node_load_v1: 3985448476 + node_save_v1: 133442320 stable_memory_size: 242 btreemap_insert_blob_1024_16_v2: measurements: - instructions: 5358731374 - node_load_v2: 4195507437 - node_save_v2: 193208733 + instructions: 5204903603 + node_load_v2: 4095654733 + node_save_v2: 158980711 stable_memory_size: 182 btreemap_insert_blob_1024_256: measurements: - instructions: 5130740072 - node_load_v1: 4039224210 - node_save_v1: 201310396 + instructions: 4998981709 + node_load_v1: 3965654660 + node_save_v1: 161983415 stable_memory_size: 293 btreemap_insert_blob_1024_256_v2: measurements: - instructions: 5352948952 - node_load_v2: 4171364974 - node_save_v2: 221531887 + instructions: 5197123201 + node_load_v2: 4070258951 + node_save_v2: 187329183 stable_memory_size: 220 btreemap_insert_blob_1024_32: measurements: - instructions: 5089791785 - node_load_v1: 4079908295 - node_save_v1: 173954636 + instructions: 4958594629 + node_load_v1: 4005822869 + node_save_v1: 134559317 stable_memory_size: 240 btreemap_insert_blob_1024_32_v2: measurements: - instructions: 5357513466 - node_load_v2: 4214236378 - node_save_v2: 194114909 + instructions: 5202700273 + node_load_v2: 4113362166 + node_save_v2: 159929338 stable_memory_size: 181 btreemap_insert_blob_1024_4: measurements: - instructions: 4968257212 - node_load_v1: 4058890666 - node_save_v1: 162657999 + instructions: 4840591273 + node_load_v1: 3985365549 + node_save_v1: 124687423 stable_memory_size: 236 btreemap_insert_blob_1024_4_v2: measurements: - instructions: 5264404231 - node_load_v2: 4189301776 - node_save_v2: 182905394 + instructions: 5113551566 + node_load_v2: 4089690715 + node_save_v2: 150184318 stable_memory_size: 177 btreemap_insert_blob_1024_512: measurements: - instructions: 5224338924 - node_load_v1: 4064093845 - node_save_v1: 236696639 + instructions: 5087635883 + node_load_v1: 3989806728 + node_save_v1: 193925745 stable_memory_size: 349 btreemap_insert_blob_1024_512_v2: measurements: - instructions: 5481571968 - node_load_v2: 4201549676 - node_save_v2: 257610609 + instructions: 5320097350 + node_load_v2: 4099519139 + node_save_v2: 219719584 stable_memory_size: 262 btreemap_insert_blob_1024_64: measurements: - instructions: 5110806943 - node_load_v1: 4075394290 - node_save_v1: 178905580 + instructions: 4979331968 + node_load_v1: 4001759787 + node_save_v1: 139286228 stable_memory_size: 251 btreemap_insert_blob_1024_64_v2: measurements: - instructions: 5377434456 - node_load_v2: 4214020891 - node_save_v2: 199157099 + instructions: 5221310486 + node_load_v2: 4112538215 + node_save_v2: 164772561 stable_memory_size: 189 btreemap_insert_blob_1024_8: measurements: - instructions: 5053776980 - node_load_v1: 4051194851 - node_save_v1: 167362943 + instructions: 4924885892 + node_load_v1: 3978237186 + node_save_v1: 128434218 stable_memory_size: 238 btreemap_insert_blob_1024_8_v2: measurements: - instructions: 5331593907 - node_load_v2: 4181516149 - node_save_v2: 187604446 + instructions: 5179644486 + node_load_v2: 4082400473 + node_save_v2: 153945446 stable_memory_size: 179 btreemap_insert_blob_128_1024: measurements: - instructions: 1577091213 - node_load_v1: 812526962 - node_save_v1: 301462572 + instructions: 1437616292 + node_load_v1: 739027550 + node_save_v1: 257309360 stable_memory_size: 261 btreemap_insert_blob_128_1024_v2: measurements: - instructions: 1726441521 - node_load_v2: 925130424 - node_save_v2: 322015815 + instructions: 1565933845 + node_load_v2: 826942435 + node_save_v2: 283053248 stable_memory_size: 196 btreemap_insert_blob_16_1024: measurements: - instructions: 992366717 - node_load_v1: 322073344 - node_save_v1: 291094888 + instructions: 858846535 + node_load_v1: 253207451 + node_save_v1: 248356858 stable_memory_size: 216 btreemap_insert_blob_16_1024_v2: measurements: - instructions: 1108674244 - node_load_v2: 419541518 - node_save_v2: 310638874 + instructions: 960083194 + node_load_v2: 330853838 + node_save_v2: 273042097 stable_memory_size: 162 btreemap_insert_blob_256_1024: measurements: - instructions: 2114284649 - node_load_v1: 1278881721 - node_save_v1: 300728644 + instructions: 1974624891 + node_load_v1: 1204369041 + node_save_v1: 256351524 stable_memory_size: 293 btreemap_insert_blob_256_1024_v2: measurements: - instructions: 2273386999 - node_load_v2: 1395147359 - node_save_v2: 321544817 + instructions: 2111102480 + node_load_v2: 1294504838 + node_save_v2: 282314461 stable_memory_size: 220 btreemap_insert_blob_32_1024: measurements: - instructions: 1041724177 - node_load_v1: 358626551 - node_save_v1: 298295476 + instructions: 904010965 + node_load_v1: 286588753 + node_save_v1: 254796471 stable_memory_size: 231 btreemap_insert_blob_32_1024_v2: measurements: - instructions: 1156895178 - node_load_v2: 459271136 - node_save_v2: 316798162 + instructions: 1004184959 + node_load_v2: 366954442 + node_save_v2: 278850203 stable_memory_size: 174 btreemap_insert_blob_4_1024: measurements: - instructions: 772106359 - node_load_v1: 212848724 - node_save_v1: 267119730 + instructions: 652382785 + node_load_v1: 149831245 + node_save_v1: 228197043 stable_memory_size: 124 btreemap_insert_blob_4_1024_v2: measurements: - instructions: 862904908 - node_load_v2: 286322995 - node_save_v2: 284380143 + instructions: 736453619 + node_load_v2: 212173910 + node_save_v2: 250260310 stable_memory_size: 93 btreemap_insert_blob_512_1024: measurements: - instructions: 3195541992 - node_load_v1: 2200910325 - node_save_v1: 306828402 + instructions: 3053462673 + node_load_v1: 2124633848 + node_save_v1: 261440735 stable_memory_size: 352 btreemap_insert_blob_512_1024_v2: measurements: - instructions: 3317431106 - node_load_v2: 2302979370 - node_save_v2: 323365428 + instructions: 3155320531 + node_load_v2: 2201526645 + node_save_v2: 283885891 stable_memory_size: 264 btreemap_insert_blob_64_1024: measurements: - instructions: 1305958991 - node_load_v1: 584672643 - node_save_v1: 300400388 + instructions: 1166106772 + node_load_v1: 510883301 + node_save_v1: 256301205 stable_memory_size: 246 btreemap_insert_blob_64_1024_v2: measurements: - instructions: 1439210453 - node_load_v2: 692993072 - node_save_v2: 319569550 + instructions: 1279910739 + node_load_v2: 595578889 + node_save_v2: 280900588 stable_memory_size: 184 btreemap_insert_blob_8_1024: measurements: - instructions: 905706875 - node_load_v1: 247335003 - node_save_v1: 284445265 + instructions: 776453148 + node_load_v1: 179790788 + node_save_v1: 242797687 stable_memory_size: 184 btreemap_insert_blob_8_1024_v2: measurements: - instructions: 1002633716 - node_load_v2: 325787553 - node_save_v2: 303101882 + instructions: 866232312 + node_load_v2: 246352950 + node_save_v2: 266596061 stable_memory_size: 139 btreemap_insert_blob_8_u64: measurements: - instructions: 589493749 - node_load_v1: 243685209 - node_save_v1: 164111004 + instructions: 472686878 + node_load_v1: 181986700 + node_save_v1: 126883358 stable_memory_size: 7 btreemap_insert_blob_8_u64_v2: measurements: - instructions: 697133799 - node_load_v2: 329438301 - node_save_v2: 184403609 + instructions: 566706828 + node_load_v2: 250601037 + node_save_v2: 151769417 stable_memory_size: 5 btreemap_insert_u64_blob_8: measurements: - instructions: 611656296 - node_load_v1: 233854938 - node_save_v1: 203753854 + instructions: 480324223 + node_load_v1: 170565445 + node_save_v1: 153183226 stable_memory_size: 8 btreemap_insert_u64_blob_8_v2: measurements: - instructions: 679823522 - node_load_v2: 294338080 - node_save_v2: 211575679 + instructions: 548609694 + node_load_v2: 224781217 + node_save_v2: 168239993 stable_memory_size: 6 btreemap_insert_u64_u64: measurements: - instructions: 627664728 - node_load_v1: 234409394 - node_save_v1: 211208718 + instructions: 494167871 + node_load_v1: 171859779 + node_save_v1: 159769002 stable_memory_size: 8 btreemap_insert_u64_u64_v2: measurements: - instructions: 703623870 - node_load_v2: 300411584 - node_save_v2: 220348622 + instructions: 569015520 + node_load_v2: 230782820 + node_save_v2: 175856694 stable_memory_size: 7 +btreemap_iter_count_10mib_values: + measurements: + instructions: 23627527 + node_load_v2: 402287 + stable_memory_size: 33 +btreemap_iter_count_small_values: + measurements: + instructions: 27195467 + node_load_v2: 6367125 + stable_memory_size: 32 btreemap_remove_blob_128_1024: measurements: - instructions: 1957356649 - node_load_v1: 914434789 - node_save_v1: 514074570 + instructions: 1765436627 + node_load_v1: 831238789 + node_save_v1: 435218602 stable_memory_size: 261 btreemap_remove_blob_128_1024_v2: measurements: - instructions: 2117203127 - node_load_v2: 1032337866 - node_save_v2: 556162319 + instructions: 1910258373 + node_load_v2: 925249945 + node_save_v2: 487653874 stable_memory_size: 196 btreemap_remove_blob_16_1024: measurements: - instructions: 1247951670 - node_load_v1: 371456037 - node_save_v1: 473518008 + instructions: 1070289873 + node_load_v1: 293118687 + node_save_v1: 401442409 stable_memory_size: 216 btreemap_remove_blob_16_1024_v2: measurements: - instructions: 1391842517 - node_load_v2: 479235617 - node_save_v2: 512046945 + instructions: 1203248521 + node_load_v2: 381414821 + node_save_v2: 449480819 stable_memory_size: 162 btreemap_remove_blob_256_1024: measurements: - instructions: 2573453911 - node_load_v1: 1428465620 - node_save_v1: 511120662 + instructions: 2382407241 + node_load_v1: 1344675202 + node_save_v1: 432970452 stable_memory_size: 293 btreemap_remove_blob_256_1024_v2: measurements: - instructions: 2738027594 - node_load_v2: 1548255619 - node_save_v2: 551257725 + instructions: 2530218035 + node_load_v2: 1439645617 + node_save_v2: 483420926 stable_memory_size: 220 btreemap_remove_blob_32_1024: measurements: - instructions: 1324817959 - node_load_v1: 403513191 - node_save_v1: 492234126 + instructions: 1140153781 + node_load_v1: 322843280 + node_save_v1: 417148893 stable_memory_size: 231 btreemap_remove_blob_32_1024_v2: measurements: - instructions: 1476050369 - node_load_v2: 519013227 - node_save_v2: 532132813 + instructions: 1278111352 + node_load_v2: 415907179 + node_save_v2: 466999763 stable_memory_size: 174 btreemap_remove_blob_4_1024: measurements: - instructions: 807721649 - node_load_v1: 233144442 - node_save_v1: 306452731 + instructions: 674418478 + node_load_v1: 164435030 + node_save_v1: 259959839 stable_memory_size: 124 btreemap_remove_blob_4_1024_v2: measurements: - instructions: 913517563 - node_load_v2: 314086802 - node_save_v2: 331046095 + instructions: 773931207 + node_load_v2: 233938221 + node_save_v2: 290606040 stable_memory_size: 93 btreemap_remove_blob_512_1024: measurements: - instructions: 3867652464 - node_load_v1: 2474030645 - node_save_v1: 527547819 + instructions: 3671936473 + node_load_v1: 2390036799 + node_save_v1: 446122393 stable_memory_size: 352 btreemap_remove_blob_512_1024_v2: measurements: - instructions: 4041285449 - node_load_v2: 2600718246 - node_save_v2: 569534896 + instructions: 3826090329 + node_load_v2: 2488915437 + node_save_v2: 498703262 stable_memory_size: 264 btreemap_remove_blob_64_1024: measurements: - instructions: 1639040548 - node_load_v1: 661396112 - node_save_v1: 505335855 + instructions: 1448155157 + node_load_v1: 577581483 + node_save_v1: 428020659 stable_memory_size: 246 btreemap_remove_blob_64_1024_v2: measurements: - instructions: 1795315618 - node_load_v2: 778335609 - node_save_v2: 546167574 + instructions: 1590358981 + node_load_v2: 671421671 + node_save_v2: 479097166 stable_memory_size: 184 btreemap_remove_blob_8_1024: measurements: - instructions: 1038596601 - node_load_v1: 278756927 - node_save_v1: 408063372 + instructions: 877475340 + node_load_v1: 203792348 + node_save_v1: 345768939 stable_memory_size: 184 btreemap_remove_blob_8_1024_v2: measurements: - instructions: 1150784585 - node_load_v2: 359148126 - node_save_v2: 441289916 + instructions: 986682953 + node_load_v2: 274023708 + node_save_v2: 387155036 stable_memory_size: 139 btreemap_remove_blob_8_u64: measurements: - instructions: 756190189 - node_load_v1: 271109869 - node_save_v1: 258955340 + instructions: 607672459 + node_load_v1: 202072945 + node_save_v1: 200360852 stable_memory_size: 7 btreemap_remove_blob_8_u64_v2: measurements: - instructions: 902070967 - node_load_v2: 371425008 - node_save_v2: 300237913 + instructions: 739316591 + node_load_v2: 283135159 + node_save_v2: 248529586 stable_memory_size: 5 btreemap_remove_u64_blob_8: measurements: - instructions: 846321611 - node_load_v1: 263317086 - node_save_v1: 354096302 + instructions: 669856911 + node_load_v1: 192918268 + node_save_v1: 269708119 stable_memory_size: 8 btreemap_remove_u64_blob_8_v2: measurements: - instructions: 935942012 - node_load_v2: 329460173 - node_save_v2: 373120565 + instructions: 765304028 + node_load_v2: 253212163 + node_save_v2: 302212433 stable_memory_size: 6 btreemap_remove_u64_u64: measurements: - instructions: 874256488 - node_load_v1: 264707458 - node_save_v1: 370018389 + instructions: 693077801 + node_load_v1: 193826722 + node_save_v1: 283366051 stable_memory_size: 8 btreemap_remove_u64_u64_v2: measurements: - instructions: 976419924 - node_load_v2: 337138522 - node_save_v2: 394608862 + instructions: 797832204 + node_load_v2: 258765788 + node_save_v2: 320071273 stable_memory_size: 7 memory_manager_baseline: measurements: - instructions: 1144 + instructions: 1122 stable_memory_size: 8000 memory_manager_grow: measurements: - instructions: 287018881 + instructions: 284711825 stable_memory_size: 32001 memory_manager_overhead: measurements: - instructions: 4605248 + instructions: 4523476 stable_memory_size: 8321 vec_get_blob_128: measurements: - instructions: 22055455 + instructions: 20697043 stable_memory_size: 20 vec_get_blob_16: measurements: - instructions: 11055138 + instructions: 9639316 stable_memory_size: 3 vec_get_blob_32: measurements: - instructions: 11849080 + instructions: 10445322 stable_memory_size: 6 vec_get_blob_4: measurements: - instructions: 6830239 + instructions: 5683767 stable_memory_size: 1 vec_get_blob_64: measurements: - instructions: 16495665 + instructions: 15108707 stable_memory_size: 10 vec_get_blob_8: measurements: - instructions: 8222880 + instructions: 6902502 stable_memory_size: 2 vec_get_u64: measurements: - instructions: 7450346 + instructions: 6170324 stable_memory_size: 2 vec_insert_blob_128: measurements: - instructions: 4942837 + instructions: 3682815 stable_memory_size: 20 vec_insert_blob_16: measurements: - instructions: 4880610 + instructions: 3680588 stable_memory_size: 3 vec_insert_blob_32: measurements: - instructions: 4941003 + instructions: 3680981 stable_memory_size: 6 vec_insert_blob_4: measurements: - instructions: 4940348 + instructions: 3680326 stable_memory_size: 1 vec_insert_blob_64: measurements: - instructions: 4941527 + instructions: 3681505 stable_memory_size: 10 vec_insert_blob_8: measurements: - instructions: 4940479 + instructions: 3680457 stable_memory_size: 2 vec_insert_u64: measurements: - instructions: 7600479 + instructions: 5710457 stable_memory_size: 2