@@ -44,7 +44,7 @@ fn bench_update_family<F: Family>(c: &mut Criterion, runner: &tokio::Runner, fam
4444 module_path!( ) ,
4545 ) ,
4646 |b| {
47- b. to_async ( runner) . iter_custom ( |_iters | async move {
47+ b. to_async ( runner) . iter_custom ( |iters | async move {
4848 let pool = match strategy {
4949 Strategy :: BatchedParallel => {
5050 let ctx = context:: get :: < commonware_runtime:: tokio:: Context > ( ) ;
@@ -74,43 +74,45 @@ fn bench_update_family<F: Family>(c: &mut Criterion, runner: &tokio::Runner, fam
7474
7575 // Randomly update leaves -- this is what we are benchmarking.
7676 let start = Instant :: now ( ) ;
77+ for _ in 0 ..iters {
78+ // Simulate leaf-batching being the responsibility of the caller.
79+ let mut leaf_map = HashMap :: new ( ) ;
80+ for _ in 0 ..updates {
81+ let rand_leaf_num = sampler. gen_range ( 0 ..leaves) ;
82+ let rand_leaf_loc = leaf_locations[ rand_leaf_num] ;
83+ let rand_leaf_swap = sampler. gen_range ( 0 ..elements. len ( ) ) ;
84+ let new_element = & elements[ rand_leaf_swap] ;
85+ leaf_map. insert ( rand_leaf_loc, * new_element) ;
86+ }
7787
78- // Simulate leaf-batching being the responsibility of the caller.
79- let mut leaf_map = HashMap :: new ( ) ;
80- for _ in 0 ..updates {
81- let rand_leaf_num = sampler. gen_range ( 0 ..leaves) ;
82- let rand_leaf_loc = leaf_locations[ rand_leaf_num] ;
83- let rand_leaf_swap = sampler. gen_range ( 0 ..elements. len ( ) ) ;
84- let new_element = & elements[ rand_leaf_swap] ;
85- leaf_map. insert ( rand_leaf_loc, * new_element) ;
86- }
87-
88- match strategy {
89- Strategy :: NoBatching => {
90- for ( loc, element) in & leaf_map {
91- let batch =
92- mem. new_batch ( ) . update_leaf ( & h, * loc, element) . unwrap ( ) ;
93- let batch = batch. merkleize ( & mem, & h) ;
88+ match strategy {
89+ Strategy :: NoBatching => {
90+ for ( loc, element) in & leaf_map {
91+ let batch = mem
92+ . new_batch ( )
93+ . update_leaf ( & h, * loc, element)
94+ . unwrap ( ) ;
95+ let batch = batch. merkleize ( & mem, & h) ;
96+ mem. apply_batch ( & batch) . unwrap ( ) ;
97+ }
98+ }
99+ _ => {
100+ let updates: Vec < (
101+ Location < F > ,
102+ commonware_cryptography:: sha256:: Digest ,
103+ ) > = leaf_map. into_iter ( ) . collect ( ) ;
104+ let batch = {
105+ let mut batch = mem. new_batch ( ) ;
106+ if let Some ( ref p) = pool {
107+ batch = batch. with_pool ( Some ( p. clone ( ) ) ) ;
108+ }
109+ batch = batch. update_leaf_batched ( & updates) . unwrap ( ) ;
110+ batch. merkleize ( & mem, & h)
111+ } ;
94112 mem. apply_batch ( & batch) . unwrap ( ) ;
95113 }
96114 }
97- _ => {
98- let updates: Vec < (
99- Location < F > ,
100- commonware_cryptography:: sha256:: Digest ,
101- ) > = leaf_map. into_iter ( ) . collect ( ) ;
102- let batch = {
103- let mut batch = mem. new_batch ( ) ;
104- if let Some ( ref p) = pool {
105- batch = batch. with_pool ( Some ( p. clone ( ) ) ) ;
106- }
107- batch = batch. update_leaf_batched ( & updates) . unwrap ( ) ;
108- batch. merkleize ( & mem, & h)
109- } ;
110- mem. apply_batch ( & batch) . unwrap ( ) ;
111- }
112115 }
113-
114116 start. elapsed ( )
115117 } ) ;
116118 } ,
0 commit comments