Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ default = ["concurrent_stat"]
concurrent_stat = []

[dependencies]
arr_macro = "0.1.3"
crossbeam-epoch = "0.9.5"
crossbeam-utils = "0.8.5"
either = "1.6.1"
parking_lot = "0.12.1"
rand = "0.8.4"
thread_local = "1.1.4"
parking_lot = "0.12.1"
uninit = "0.5.1"

[dev-dependencies]
criterion = "0.3.4"
num_cpus = "1.13.0"
crossbeam-queue = "0.3.5"
num_cpus = "1.13.0"

[[bench]]
name = "stack"
Expand Down
12 changes: 5 additions & 7 deletions benches/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const OPS_RATE: [(usize, usize, usize); 7] = [
(50, 0, 50),
];

fn bench_vs_btreemap(c: &mut Criterion) {
fn bench_u64_vs_btreemap(c: &mut Criterion) {
for (insert, lookup, remove) in OPS_RATE {
let logs = fuzz_sequential_logs(
200,
Expand All @@ -42,12 +42,10 @@ fn bench_vs_btreemap(c: &mut Criterion) {
group.throughput(Throughput::Elements(MAP_TOTAL_OPS as u64));

bench_logs_btreemap(logs.clone(), &mut group);
bench_logs_sequential_map::<BTree<_, _>>("BTree", logs.clone(), &mut group);
bench_logs_sequential_map::<AVLTree<_, _>>("AVLTree", logs, &mut group);
bench_logs_sequential_map::<u64, u64, BTree<_, _>>("BTree", logs.clone(), &mut group);
bench_logs_sequential_map::<u64, u64, AVLTree<_, _>>("AVLTree", logs, &mut group);
}
}

criterion_group!(bench, bench_vs_btreemap);
criterion_main! {
bench,
}
criterion_group!(bench, bench_u64_vs_btreemap);
criterion_main! {bench}
70 changes: 44 additions & 26 deletions benches/util/sequential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,60 @@ use std::{
time::{Duration, Instant},
};

use cds::{map::SequentialMap, queue::SequentialQueue};
use cds::{map::SequentialMap, queue::SequentialQueue, util::random::Random};
use criterion::{black_box, measurement::WallTime, BenchmarkGroup};
use rand::{prelude::SliceRandom, thread_rng, Rng};

#[derive(Clone, Copy)]
pub enum Op {
Insert(u64),
Lookup(u64),
Remove(u64),
pub enum Op<K, V> {
Insert(K, V),
Lookup(K),
Remove(K),
}

pub fn fuzz_sequential_logs(
type Logs<K, V> = Vec<(Vec<(K, V)>, Vec<Op<K, V>>)>;

pub fn fuzz_sequential_logs<K: Ord + Clone + Random, V: Clone + Random>(
iters: u64,
already_inserted: u64,
insert: usize,
lookup: usize,
remove: usize,
) -> Vec<(Vec<u64>, Vec<Op>)> {
) -> Logs<K, V> {
let mut rng = thread_rng();
let mut result = Vec::new();

for _ in 0..iters {
let mut logs = Vec::new();

let mut pre_inserted: Vec<u64> = (0..already_inserted).collect();
pre_inserted.shuffle(&mut rng);
let mut pre_inserted = Vec::new();

for _ in 0..already_inserted {
pre_inserted.push((K::gen(&mut rng), V::gen(&mut rng)));
}

for _ in 0..insert {
logs.push(Op::Insert(rng.gen_range(already_inserted..u64::MAX)));
logs.push(Op::Insert(K::gen(&mut rng), V::gen(&mut rng)));
}

for _ in 0..lookup {
logs.push(Op::Lookup(rng.gen_range(0..already_inserted)));
for i in 0..lookup {
if i % 2 == 0 {
logs.push(Op::Lookup(K::gen(&mut rng)));
} else {
logs.push(Op::Lookup(
pre_inserted.choose(&mut rng).cloned().unwrap().0,
));
}
}

for _ in 0..remove {
logs.push(Op::Remove(rng.gen_range(0..already_inserted)));
for i in 0..remove {
if i % 2 == 0 {
logs.push(Op::Remove(K::gen(&mut rng)));
} else {
logs.push(Op::Remove(
pre_inserted.choose(&mut rng).cloned().unwrap().0,
));
}
}

logs.shuffle(&mut rng);
Expand Down Expand Up @@ -84,7 +101,7 @@ where
});
}

pub fn bench_logs_btreemap(mut logs: Vec<(Vec<u64>, Vec<Op>)>, c: &mut BenchmarkGroup<WallTime>) {
pub fn bench_logs_btreemap<K: Ord, V>(mut logs: Logs<K, V>, c: &mut BenchmarkGroup<WallTime>) {
c.bench_function("std::BTreeMap", |b| {
b.iter_custom(|iters| {
let mut duration = Duration::ZERO;
Expand All @@ -94,15 +111,15 @@ pub fn bench_logs_btreemap(mut logs: Vec<(Vec<u64>, Vec<Op>)>, c: &mut Benchmark
let mut map = BTreeMap::new();

// pre-insert
for key in pre_inserted {
let _ = map.insert(key, key);
for (key, value) in pre_inserted {
let _ = map.insert(key, value);
}

let start = Instant::now();
for op in logs {
match op {
Op::Insert(key) => {
let _ = black_box(map.insert(key, key));
Op::Insert(key, value) => {
let _ = black_box(map.insert(key, value));
}
Op::Lookup(key) => {
let _ = black_box(map.get(&key));
Expand All @@ -120,12 +137,13 @@ pub fn bench_logs_btreemap(mut logs: Vec<(Vec<u64>, Vec<Op>)>, c: &mut Benchmark
});
}

pub fn bench_logs_sequential_map<M>(
pub fn bench_logs_sequential_map<K, V, M>(
name: &str,
mut logs: Vec<(Vec<u64>, Vec<Op>)>,
mut logs: Logs<K, V>,
c: &mut BenchmarkGroup<WallTime>,
) where
M: SequentialMap<u64, u64>,
K: Eq + Random,
M: SequentialMap<K, V>,
{
c.bench_function(name, |b| {
b.iter_custom(|iters| {
Expand All @@ -136,15 +154,15 @@ pub fn bench_logs_sequential_map<M>(
let mut map = M::new();

// pre-insert
for key in pre_inserted {
let _ = map.insert(&key, key);
for (key, value) in pre_inserted {
let _ = map.insert(&key, value);
}

let start = Instant::now();
for op in logs {
match op {
Op::Insert(key) => {
let _ = black_box(map.insert(&key, key));
Op::Insert(key, value) => {
let _ = black_box(map.insert(&key, value));
}
Op::Lookup(key) => {
let _ = black_box(map.lookup(&key));
Expand Down
Loading