mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-08 22:28:12 -05:00
bench: crossbeam benchmark use the same group so we can directly compare lockless vs mutex
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user