mirror of https://github.com/xacrimon/dashmap
std_rwlock and dashmap benches.
This commit is contained in:
parent
ac7590e3fb
commit
fb26429ab7
12
Cargo.toml
12
Cargo.toml
|
@ -15,6 +15,18 @@ categories = ["concurrency", "algorithms", "data-structures"]
|
|||
[features]
|
||||
nightly = ["parking_lot/nightly", "dashmap-shard/nightly"]
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
rayon = "1.2.0"
|
||||
|
||||
[[bench]]
|
||||
name = "rwlock_std"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "dashmap"
|
||||
harness = false
|
||||
|
||||
[dependencies]
|
||||
dashmap-shard = { version = "0.1.1", default-features = false }
|
||||
parking_lot = "0.9.0"
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId, Throughput};
|
||||
use rayon::prelude::*;
|
||||
use dashmap::DashMap;
|
||||
|
||||
const ITER: u64 = 32 * 1024;
|
||||
|
||||
fn task_insert_dashmap_u64_u64() -> DashMap<u64, u64> {
|
||||
let map = DashMap::new();
|
||||
(0..ITER).into_par_iter().for_each(|i| {
|
||||
map.insert(i, i + 7);
|
||||
});
|
||||
map
|
||||
}
|
||||
|
||||
fn insert_dashmap_u64_u64(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("insert_dashmap_u64_u64");
|
||||
group.throughput(Throughput::Elements(ITER as u64));
|
||||
let max = num_cpus::get();
|
||||
|
||||
for threads in 1..=max {
|
||||
group.bench_with_input(BenchmarkId::from_parameter(threads), &threads, |b, &threads| {
|
||||
let pool = rayon::ThreadPoolBuilder::new().num_threads(threads).build().unwrap();
|
||||
pool.install(|| b.iter(|| task_insert_dashmap_u64_u64()));
|
||||
});
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, insert_dashmap_u64_u64);
|
||||
criterion_main!(benches);
|
|
@ -0,0 +1,32 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId, Throughput};
|
||||
use rayon::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::RwLock;
|
||||
|
||||
const ITER: u64 = 2 * 1024;
|
||||
|
||||
fn task_insert_rwlock_std_u64_u64() -> RwLock<HashMap<u64, u64>> {
|
||||
let map = RwLock::new(HashMap::new());
|
||||
(0..ITER).into_par_iter().for_each(|i| {
|
||||
map.write().unwrap().insert(i, i + 7);
|
||||
});
|
||||
map
|
||||
}
|
||||
|
||||
fn insert_rwlock_std_u64_u64(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("insert_rwlock_std_u64_u64");
|
||||
group.throughput(Throughput::Elements(ITER as u64));
|
||||
let max = num_cpus::get();
|
||||
|
||||
for threads in 1..=max {
|
||||
group.bench_with_input(BenchmarkId::from_parameter(threads), &threads, |b, &threads| {
|
||||
let pool = rayon::ThreadPoolBuilder::new().num_threads(threads).build().unwrap();
|
||||
pool.install(|| b.iter(|| task_insert_rwlock_std_u64_u64()));
|
||||
});
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, insert_rwlock_std_u64_u64);
|
||||
criterion_main!(benches);
|
|
@ -14,7 +14,7 @@ use std::hash::{BuildHasher, Hash, Hasher};
|
|||
use t::Map;
|
||||
|
||||
fn shard_amount() -> usize {
|
||||
(num_cpus::get() * 4).next_power_of_two()
|
||||
(num_cpus::get() * 32).next_power_of_two()
|
||||
}
|
||||
|
||||
fn ncb(shard_amount: usize) -> usize {
|
||||
|
|
Loading…
Reference in New Issue