|
@@ -29,7 +29,7 @@ use std::{
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
fn crossbeam(c: &mut Criterion) {
|
|
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 {
|
|
for k in 1..10 {
|
|
|
let stopped = Arc::new(AtomicBool::new(false));
|
|
let stopped = Arc::new(AtomicBool::new(false));
|
|
@@ -54,7 +54,7 @@ fn crossbeam(c: &mut Criterion) {
|
|
|
.run();
|
|
.run();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- group.bench_with_input(BenchmarkId::from_parameter(k), &k, |b, &_| {
|
|
|
|
|
|
|
+ group.bench_with_input(BenchmarkId::new("crossbeam", k), &k, |b, &_| {
|
|
|
b.iter_batched(
|
|
b.iter_batched(
|
|
|
|| {
|
|
|| {
|
|
|
let key: usize = OsRng.gen();
|
|
let key: usize = OsRng.gen();
|
|
@@ -62,7 +62,6 @@ fn crossbeam(c: &mut Criterion) {
|
|
|
(key, val)
|
|
(key, val)
|
|
|
},
|
|
},
|
|
|
|(key, val)| {
|
|
|(key, val)| {
|
|
|
- // Do 10k inserts
|
|
|
|
|
map.insert(key, val);
|
|
map.insert(key, val);
|
|
|
},
|
|
},
|
|
|
BatchSize::SmallInput,
|
|
BatchSize::SmallInput,
|
|
@@ -73,12 +72,9 @@ fn crossbeam(c: &mut Criterion) {
|
|
|
parallel_inserts.join().unwrap();
|
|
parallel_inserts.join().unwrap();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- group.finish();
|
|
|
|
|
-
|
|
|
|
|
// Now try normal Mutex hashmap
|
|
// Now try normal Mutex hashmap
|
|
|
// This is not an async Mutex, but async Mutexes are always slower than sync ones anyway
|
|
// 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.
|
|
// 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 {
|
|
for k in 1..10 {
|
|
|
let stopped = Arc::new(AtomicBool::new(false));
|
|
let stopped = Arc::new(AtomicBool::new(false));
|
|
@@ -103,7 +99,7 @@ fn crossbeam(c: &mut Criterion) {
|
|
|
.run();
|
|
.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(
|
|
b.iter_batched(
|
|
|
|| {
|
|
|| {
|
|
|
let key: usize = OsRng.gen();
|
|
let key: usize = OsRng.gen();
|
|
@@ -111,7 +107,6 @@ fn crossbeam(c: &mut Criterion) {
|
|
|
(key, val)
|
|
(key, val)
|
|
|
},
|
|
},
|
|
|
|(key, val)| {
|
|
|(key, val)| {
|
|
|
- // Do 10k inserts
|
|
|
|
|
map.lock().unwrap().insert(key, val);
|
|
map.lock().unwrap().insert(key, val);
|
|
|
},
|
|
},
|
|
|
BatchSize::SmallInput,
|
|
BatchSize::SmallInput,
|
|
@@ -121,8 +116,6 @@ fn crossbeam(c: &mut Criterion) {
|
|
|
stopped.store(true, Ordering::Relaxed);
|
|
stopped.store(true, Ordering::Relaxed);
|
|
|
parallel_inserts.join().unwrap();
|
|
parallel_inserts.join().unwrap();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- group.finish();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(bench, crossbeam);
|
|
criterion_group!(bench, crossbeam);
|