From 9a76aa26e77456526cb9b534bb250ea1c78221cf Mon Sep 17 00:00:00 2001 From: darkfi Date: Wed, 12 Jun 2024 13:03:07 +0200 Subject: [PATCH] bench: crossbeam benchmark use the same group so we can directly compare lockless vs mutex --- bench/crossbeam.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/bench/crossbeam.rs b/bench/crossbeam.rs index 7f21a59de..cb7ccaf6c 100644 --- a/bench/crossbeam.rs +++ b/bench/crossbeam.rs @@ -29,7 +29,7 @@ use std::{ }; fn crossbeam(c: &mut Criterion) { - let mut group = c.benchmark_group("crossbeam"); + let mut group = c.benchmark_group("crossbeam_vs_mutex-hashmap"); for k in 1..10 { let stopped = Arc::new(AtomicBool::new(false)); @@ -54,7 +54,7 @@ fn crossbeam(c: &mut Criterion) { .run(); }); - group.bench_with_input(BenchmarkId::from_parameter(k), &k, |b, &_| { + group.bench_with_input(BenchmarkId::new("crossbeam", k), &k, |b, &_| { b.iter_batched( || { let key: usize = OsRng.gen(); @@ -62,7 +62,6 @@ fn crossbeam(c: &mut Criterion) { (key, val) }, |(key, val)| { - // Do 10k inserts map.insert(key, val); }, BatchSize::SmallInput, @@ -73,12 +72,9 @@ fn crossbeam(c: &mut Criterion) { parallel_inserts.join().unwrap(); } - group.finish(); - // Now try normal Mutex hashmap // This is not an async Mutex, but async Mutexes are always slower than sync ones anyway // since they just implement an async interface on top of sync Mutexes. - let mut group = c.benchmark_group("mutex_hashmap"); for k in 1..10 { let stopped = Arc::new(AtomicBool::new(false)); @@ -103,7 +99,7 @@ fn crossbeam(c: &mut Criterion) { .run(); }); - group.bench_with_input(BenchmarkId::from_parameter(k), &k, |b, &_| { + group.bench_with_input(BenchmarkId::new("mutex_hashmap", k), &k, |b, &_| { b.iter_batched( || { let key: usize = OsRng.gen(); @@ -111,7 +107,6 @@ fn crossbeam(c: &mut Criterion) { (key, val) }, |(key, val)| { - // Do 10k inserts map.lock().unwrap().insert(key, val); }, BatchSize::SmallInput, @@ -121,8 +116,6 @@ fn crossbeam(c: &mut Criterion) { stopped.store(true, Ordering::Relaxed); parallel_inserts.join().unwrap(); } - - group.finish(); } criterion_group!(bench, crossbeam);