From f17df80f59b45b1b1824c19ef3644ef682c9df9b Mon Sep 17 00:00:00 2001 From: Mac L Date: Wed, 30 Aug 2023 19:47:05 +1000 Subject: [PATCH 1/3] Add parallel bench --- benches/tree_hash_root.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/benches/tree_hash_root.rs b/benches/tree_hash_root.rs index e331fc1..5b3a8d2 100644 --- a/benches/tree_hash_root.rs +++ b/benches/tree_hash_root.rs @@ -43,6 +43,26 @@ pub fn tree_hash_root(c: &mut Criterion) { }) }, ); + + c.bench_with_input( + BenchmarkId::new("tree_hash_root_list_parallel", size), + &size, + |b, &size| { + b.iter(|| { + let l1 = List::::try_from_iter(0..size).unwrap(); + let mut l2 = List::::try_from_iter(0..size).unwrap(); + l2.push(99).unwrap(); + l2.apply_updates().unwrap(); + + let handle = std::thread::spawn(move || { + l1.tree_hash_root(); + l2.tree_hash_root(); + }); + + handle.join().unwrap(); + }); + }, + ); } criterion_group!(benches, tree_hash_root); From 77c59fd1aae0b21bb1aa39d46568e1f8edb5376d Mon Sep 17 00:00:00 2001 From: Mac L Date: Wed, 30 Aug 2023 20:25:16 +1000 Subject: [PATCH 2/3] Clone second list --- benches/tree_hash_root.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benches/tree_hash_root.rs b/benches/tree_hash_root.rs index 5b3a8d2..6db1fee 100644 --- a/benches/tree_hash_root.rs +++ b/benches/tree_hash_root.rs @@ -50,7 +50,7 @@ pub fn tree_hash_root(c: &mut Criterion) { |b, &size| { b.iter(|| { let l1 = List::::try_from_iter(0..size).unwrap(); - let mut l2 = List::::try_from_iter(0..size).unwrap(); + let mut l2 = l1.clone(); l2.push(99).unwrap(); l2.apply_updates().unwrap(); From 3de1addafa67a6664c436a0cbebde0409dba4146 Mon Sep 17 00:00:00 2001 From: Mac L Date: Fri, 1 Sep 2023 12:30:32 +1000 Subject: [PATCH 3/3] Use two threads --- benches/tree_hash_root.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/benches/tree_hash_root.rs b/benches/tree_hash_root.rs index 6db1fee..e15fb24 100644 --- a/benches/tree_hash_root.rs +++ b/benches/tree_hash_root.rs @@ -54,12 +54,15 @@ pub fn tree_hash_root(c: &mut Criterion) { l2.push(99).unwrap(); l2.apply_updates().unwrap(); - let handle = std::thread::spawn(move || { + let handle_1 = std::thread::spawn(move || { l1.tree_hash_root(); + }); + let handle_2 = std::thread::spawn(move || { l2.tree_hash_root(); }); - handle.join().unwrap(); + handle_1.join().unwrap(); + handle_2.join().unwrap(); }); }, );